Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"illegal qualified name in member declaration"??

1,553 views
Skip to first unread message

maxim

unread,
Nov 2, 1999, 3:00:00 AM11/2/99
to
The following compiles/runs fine...

template <class T>
class A
{
T a;
public:
A(T x=0):a(x){}
const T& GetA(){return a;}
};

class B: public A<int>
{
int b;
public:
B():b(1){}
void AB();
}b;

void B::AB()
{
cout<<GetA()<<' '<<b<<endl;
}

int main()
{
B b;
b.AB();
return 0;
}
/***************************************************************************
*****/
And I get
D:\users\max\test\temp\main.cpp(222) : error C2838: illegal qualified name
in member declaration if I nest class B inside C here:


template <class T>
class A
{
T a;
public:
A(T x=0):a(x){}
const T& GetA(){return a;}
};


class C
{

class B: public A<int>
{
int b;
public:
B():b(1){}
void AB();
}b;

void B::AB()/************ compile error here ****************/
{
cout<<GetA()<<' '<<b<<endl;
}
public:
void AB(){b.AB();}

};

int main()
{
C c;
c.AB();
return 0;
}

There is a reason I want the function definition to be outside the
declaration of B but inside C (some macro scheme I am using here). Is there
a way to get around this?
thanx,
max.

Doug Harrison

unread,
Nov 3, 1999, 3:00:00 AM11/3/99
to
maxim wrote:

Sorry, no. You either define a member function inside its class or in the
appropriate namespace scope.

--
Doug Harrison
dHar...@worldnet.att.net
Visual C++ MVP


0 new messages