I am new to C ++, so bear with me. I have a generic class named A. A has a nested class B. B contains the getB () method, which should return a new instance of B. However, I cannot compile my code. Here's what it looks like: #include
hijras
template <class E> class A { public: class B { public: int data; }; B * getB(); };
a.cpp
#include "Ah" template <class E> A<E>::B * A::getB() { return new B(); }
When I try to compile this, I get the following error:
error: expected constructor, destructor, or type conversion before '*' token
Does anyone know what I'm doing wrong?
Thanks,
helixed
UPDATE:
Thanks for the quick reply to everyone. I still have little problems with this. After making the suggestions listed here, I have something like this:
hijras
template <class E> class A { public: class B { public: int data; }; B * getB(); }; template <class E> typename A<E>::B * A<E>::getB() { return new B(); } class C { };
However, when I try to use this from main, I get an error message. Here is my main method:
main.cpp
When I try to compile this, I get the following error:
error: request for member 'getB' in 'a', which is of non-class type 'A<C>*'
Thanks again for the quick answers.
helixed
c ++ templates nested-class
Landonchropp
source share