Solved

Template issue - what's wrong with this line...?

Posted on 2000-02-14
6
174 Views
Last Modified: 2011-04-14
I am trying to compile some sample code and am getting the error:

   "..error C2059: syntax error : '<' "

on the line:

    friend class CList<NodeType>;





The entire h file Code:

///////////////////////////////////////////////////////////////////////////////
//
//  File Name
//      TEMPLATE.H
//
//  Description
//
//  Author
//      Les Thaler
//
//  Revision: 1.00
//
// Copyright (c) 1995 Microsoft Corporation. All rights reserved.
//
#ifndef _TEMPLATE_H_
#define _TEMPLATE_H_

#include <windows.h>
#include <stdio.h>
#include <mapidefs.h>

template <class NodeType> class CNode;

template <class NodeType>
class CNode
{
    friend class CList<NodeType>;      // Original line as found in the sample
    public:
        CNode(const NodeType & Type);
        ~CNode(){};
    private:
        CNode     * m_pNext;        //
        NodeType    m_Item;         // variable length, put last
};

template <class NodeType>
class CList
{
    public:
        CList();
        ~CList();
        BOOL       WINAPI Insert(const NodeType & val);
        BOOL       WINAPI InsertAsc(const NodeType & val);

        BOOL       WINAPI Delete(const NodeType &,NodeType ** ret);
        NodeType * WINAPI Find(const NodeType &SearchTarget);
        // same as Walk but doesn't copy the node
        NodeType * WINAPI Scan(BOOL bWalking = 1);
        // same as Scan but returns a copy of the node
        NodeType * WINAPI Walk(BOOL bWalking = 1);
        ULONG      WINAPI Size();
        NodeType * WINAPI Dequeue();
        VOID       WINAPI Destroy();
        BOOL       WINAPI Queue(const NodeType & val);
        CList<NodeType> & operator -=(CList<NodeType> & Deletions);
        CList<NodeType> & operator +(CList<NodeType> & Suffix);
    private:
        CNode<NodeType> * m_pHead,
                        * m_pTemp,
                        * m_pTail;      // used by Walk
        ULONG             m_ulCnt;

};

#endif

// End of file for TEMPLATE.H


0
Comment
Question by:jhattingh
  • 3
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2518417
A friend declaration is not a true declaration, so "CList<>" is not defined at that point.  Add a forward declaration like

template <class NodeType> class CList;

before the friend declatation (outside of the class.)

Let me know if you have any questions.
0
 
LVL 9

Expert Comment

by:jasonclarke
ID: 2518423
The problem is just that the compiler hasn't seen the template CList class when trying to compile CNode.

I think the forward declaration above the CNode class (which is redundant)should really be for CList, i.e. change:

template <class NodeType> class CNode;

to

template <class NodeType> class CList;

 

0
 
LVL 9

Expert Comment

by:jasonclarke
ID: 2518427
Sorry, nietod, I didn't see your comment.  I have withdrawn my answer (didn't know you could do that) since you got there first.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 22

Expert Comment

by:nietod
ID: 2518467
Wasn't mine posted as an answer?  I thought it was?

>> I have withdrawn my answer (didn't
>> know you could do that)
It was added in the latest version for this very reason and for cases where experts realize their answer is incorrect.  together with the accept comment as answer link it should make for speedier resolutions of "issues" in questions and without involving customer support personal as much.
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2518526
It was posted as a comment
0
 
LVL 22

Expert Comment

by:nietod
ID: 2518547
Opps.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

825 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