Solved

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

Posted on 2000-02-14
6
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
It was posted as a comment
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Opps.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 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

11 Experts available now in Live!

Get 1:1 Help Now