Return pointer to nested inner class from generic outer class
Posted
by helixed
on Stack Overflow
See other posts from Stack Overflow
or by helixed
Published on 2010-04-06T19:12:27Z
Indexed on
2010/04/06
19:23 UTC
Read the original article
Hit count: 529
I'm new to C++, so bear with me. I have a generic class called A. A has a nested class called B. A contains a method called getB(), which is supposed to return a new instance of B. However, I can't get my code to compile. Here's what it looks like:#include
A.h
template <class E>
class A {
public:
class B {
public:
int data;
};
B * getB();
};
A.cpp
#include "A.h"
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 anybody know what I'm doing wrong?
Thanks,
helixed
© Stack Overflow or respective owner