Skip to main content
GameDev.net gamedev.net
🔒 Locked

Declaring template class

Started by The C modest god Aug 29, 2006 at 8:24 AM 8 replies 550+ views
Original Post
The C modest god
The C modest god
I want to declare template class, somthing like this:

template <class T>
class B<T>;

template <class T>
class A {
    friend class B<T>;
};

template <class T>
class B {
};


However, I get compile errors and it seems to be wrong. How do I do that? Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Enselic
Enselic
Quote:
Original post by The C modest god
How do I do that?
Start here for example. Although the syntax is quite verbose, it isn't overly complex.
dave
dave
Can you paste the errors please?
ToohrVyk
ToohrVyk
Quote:
Original post by Nitage
If I remember correctly, templated friend declarations are illegal.


I believe you're right. However, that's not a template friend declaration — B is a class, not a template.
Nitage
Nitage
Yep, just realised my mistake.
The C modest god
The C modest god
I get syntax error: missing ';' before '<' on:

template <class T>class B<T>; // <= compilation error

It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
jflanglois
jflanglois
ToohrVyk has it right, remove from the end of your declaration:

template
class B;
The C modest god
The C modest god
Quote:
Original post by ToohrVyk
template class B; ?


It seems to work like this.
But I get a new error, not sure why. Because it worked for me before.
I get B: multiple template paramter lists are not allowed.
I didnt change any project settings.
template <class T>class B {    template <class M> // <= Error compilation    friend class B<M>;};
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
The C modest god
The C modest god
Ok, I solved this problem. Again, I should not have put the , like before.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.