Solved

Templates; making a class a friend

Posted on 2000-03-30
3
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Focus not getting shifted out of  editbox 2 69
C++ Language error 28 280
How to convert MFC::CString to UTF8 wchar_t* 10 383
sorting efficency of sorting algorithm 30 131
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

749 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