PDA

View Full Version : Simple namespace question



JPNaude
29th June 2009, 13:25
Hi

I apologize if this is more of a C++ question, but I believe that it has a really simple answer.

I'm using namespaces in one of my libraries, and I have the following:



namespace MyNameSpace {
class MyClass {
MyClass();
~MyClass();

QWidget* getWidget();
};
}


Now, whenever I call getWidget(), I get the following error message.

error: cannot convert `QWidget*' to `MyNameSpace::QWidget*' in assignment.

What am I doing wrong? I don't understand why it would think that QWidget is part of the namespace.

Thanks for any advice.
Jaco Naude

lyuts
29th June 2009, 14:16
How do you call it? Show us the source code.

wysota
29th June 2009, 16:48
You probably have a "class QWidget" or "#include <QWidget>" statement inside the namespace. Move it outside (or add it there if you don't have it already) and the problem should go away.

JPNaude
30th June 2009, 10:31
Aha! Thanks for the responses. It seems like a "class QWidget;" forward declaration did indeed slip into the wrong place inside the namespace.

Thanks for the help.