Solved

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

Posted on 2000-02-14
6
173 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 171
GUI: DIalog Stacking and Popping in MS C++ 4 65
Eclipse IDE - Cannot copy/paste from console output 8 132
VS2015 Redefinition errors 4 29
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 …
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…

895 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