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

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top