Solved

Templates; making a class a friend

Posted on 2000-03-30
3
187 Views
Last Modified: 2010-04-10
I'm almost there (after getting the answer to my more critical error earlier)....

I have two template classes. I want to make one a friend of the other so it can see the private member variables.

ListNode.h
-----------
template <class T>
class ListNode {
  friend class List<T>;
}

List.h
---------
#include "ListNode.h"

template <class T>
class List {

}

What happens is I get a "syntax error : '<' " on the line

friend class List<T>;

I've tried including "List.h" in this file, no change.

So is this possible? If so, how? What am I screwing up?

Thanks!
0
Comment
Question by:gunn
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
arikka earned 50 total points
ID: 2669928
Declaration of class List should be prior ListNode, so in ListNode.h
write forward declaration:

template <class T> class List;  

template <class T> class ListNode
{
  friend class List<T>;
}
0
 

Author Comment

by:gunn
ID: 2670049
I could have swore I tried that!

Actually, what I tried was:

template <class T> class List<T>;

and so was getting an error on the '<'. Guess I should have tried that one last combination ;)

I'm all set now!
0
 

Author Comment

by:gunn
ID: 2670050
I could have swore I tried that!

Actually, what I tried was:

template <class T> class List<T>;

and so was getting an error on the '<'. Guess I should have tried that one last combination ;)

I'm all set now!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now