Solved

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

Posted on 2000-02-14
6
176 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

705 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