PDA

View Full Version : With a namespace NM created by me, NM:: offers me a lot of data ????



tonnot
27th September 2010, 10:47
I have a own namespace in my h file, for example AAA
Later, If I write AAA:: QTCreator offers me a combo with a lot of methods, classes, etc.
I only want to see my elements, not the others
Whats happen ?
Thanks

tbscope
27th September 2010, 12:00
If shows everything available in the namespace.

tonnot
28th September 2010, 18:00
I have my own namespace, for example nms
When I write nms:: QT offers me a list with a lot of methods, but I only have one in 'myfile.h'.
Whats happen ? I only want to see my methods .
Any idea ?
Thanks

squidge
28th September 2010, 18:54
If you don't like the answer someone has given to your post, the best solution is not to repost the same question with "again:" prefixed to it.

We did notice your thread yesterday. We didn't miss it. We just decided to not reply as a suitable reply was already posted.

Zlatomir
28th September 2010, 19:12
Anyway, i can't replicate your problem, so please post a minimal example that replicate the issue, because i think you are doing some unnecessary things in there.
Like, include/using some Qt header in the namespace?

wysota
28th September 2010, 20:04
Threads merged.

Urthas
28th September 2010, 20:16
Threads merged.

I note that the icon legend does not include the icon for a merged thread. Are threads merged frequently enough to warrant inclusion? Should the icon be included in the legend regardless?

ChrisW67
28th September 2010, 23:38
The following single file input with Qt Creator 2.0.1 on Linux:


#include <QtCore>

namespace XYZZY {
int a;
class B { };
class C { };
};

class A { };
class B { };
typedef A* APtr;

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

XYZZY::
}

Produces this list when asked for completion options after the "XYZZY::" on line 17:


A (the global class A)
a (XYZZY::a)
APtr (the global typedef)
B (XYZZY::B)
C (class XYZZY::C)
main (global function)
XYZZY (the namespace itself)

The OP is asking why this list does not show only:


a
B
C

as valid completions here. I think the answer is that Qt Creator is not a full blown C++ compiler and makes some approximations when parsing the sources. AFAICT there is no way to adjust this behaviour.

tonnot
29th September 2010, 08:24
To me, it offers :

abs
advance
allocator
back_inserter
... and so on

But it is strange, it happens with this :

#ifndef WFILE2_H
#define WFILE2_H
#include <string>

using namespace std;

namespace Wfilee {
class WFileUtiles;
};

class WFileUtiles {
public:
WFileUtiles (){}
~WFileUtiles(){}
long sizefichero(string);
};

long WFileUtiles::sizefichero (string path) {
long size;
return size;
}


#endif // WFILE2_H


But not with this :

#ifndef WGEO_H
#define WGEO_H
#include <string>
using namespace std;

namespace Wgeo

{
class Wgeo;
class Wconver;
};

class Wgeo {

public:


float azimut(double,double,double,double);
};

float Wgeo::azimut(double, double, double, double){
return 0.2;
}

class Wconver {

public:
float utm_geo(int,double,double,double);
};

float Wconver::utm_geo(int, double, double, double){
return 0.2;
}

#endif // WGEO_H

It is possible than this code does not compile...

tonnot
29th September 2010, 09:11
A new problem.
If i use the 'header' namespace style , must I declare all the functions of my classes ? The compiler give me errors ...
A quick solution is to include all my code into the namespace, like this :
namespace NM {
code
code
code
....
}

Zlatomir
29th September 2010, 11:24
First issue: Don't use: using namespace std; (or any other namespace) in header files;

2) Use the same declaration in .h file and definition in .cpp file, just like you are not using namespace:


//header file
//bla.h
#ifndef BLA
#define BLA
#include <bla_bla>

namespace my_namespace {
class T {
public:
T(int);
private:
int mem;
};
}
#endif



//bla.cpp

#include "bla.h"
namespace my_namespace {
T::T(int t) {
mem = t;
}
}

ChrisW67
30th September 2010, 00:54
To me, it offers :
abs
advance
allocator
back_inserter
... and so on

When you use "using namespace std" all the names in the std namespace are exposed in the current one which is why your list is expanded to include these items. In my example, which does not expose std, none of these symbols are visible.