Template metaprogramming forward declaration

S

steprobe

Hi guys,
If I have a class like the following:

template<int Degree>
class MegaClass
{
.....
};

And then I have another class in a seperate header file, myheader.h:

class AnotherClass
{
private:
MegaClass<2> theClass;
};

What is the syntax to forward declare MegaClass<2> in myheader.h? I have
tried a few different ways, none of which have worked, and I couldn't
find anything on google.

Thanks,
Stephen
 
A

Alf P. Steinbach

* steprobe:
If I have a class like the following:

template<int Degree>
class MegaClass
{
.....
};

And then I have another class in a seperate header file, myheader.h:

class AnotherClass
{
private:
MegaClass<2> theClass;
};

What is the syntax to forward declare MegaClass<2> in myheader.h? I have
tried a few different ways, none of which have worked, and I couldn't
find anything on google.

Since you have a MegaClass<2> data member a forward declaration isn't enough.
For a declaration of a data member of type T, sizeof(T) must be well-defined.
So, just #include the header that defines the class template.


Cheers & hth.,

- Alf
 
S

steprobe

Since you have a MegaClass<2> data member a forward declaration isn't
enough. For a declaration of a data member of type T, sizeof(T) must be
well-defined. So, just #include the header that defines the class template.

Yes, of course. My mistake. If I change that member to a pointer how
might I forward declare it?
 
V

Vladimir Jovic

steprobe said:
Yes, of course. My mistake. If I change that member to a pointer how
might I forward declare it?


Like this:

template< int Degree >
class MegaClass;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top