Solved

Template problem using Object Pointer List

Posted on 1997-10-18
2
282 Views
Last Modified: 2013-11-20
I am trying to implement a pointer list which holds a list of pointers to file objects,  with a very similar
implementation to the COLLECT sample in Developer Studio 5 (see below file.cpp and file.h)

**************************************************************************************
Compiling...
file.cpp
file.h(12) : error C2239: unexpected token '<' following declaration of 'CTypedPtrList'
file.h(12) : error C2059: syntax error : '<'

file.h(21) : error C2501: 'CMyStructList' : missing decl-specifiers
file.h(21) : error C2146: syntax error : missing ';' before identifier 'm_DataSourceArray'
file.h(21) : error C2501: 'm_DataSourceArray' : missing decl-specifiers

file.cpp(14) : error C2065: 'm_DataSourceArray' : undeclared identifier
file.cpp(14) : error C2228: left of '.AddTail' must have class/struct/union type

file.cpp(15) : error C2561: 'AddFile' : function must return a value
Error executing cl.exe.

file.exe - 8 error(s), 0 warning(s)
**************************************************************************************

It is as if the compiler doesn’t understand that I am invoking a template in line 12 because it
is not recognizing '<'.

Any ideas ....

Colin

//File.cpp
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"

#include "file.h"

BOOL CFileView::AddFile()
{
  DATASOURCE* pDataSource = new DATASOURCE;
 
      pDataSource->ds_icon = 0;
  pDataSource->ds_filename = "dummy.txt";
 
      m_DataSourceArray.AddTail(pDataSource);
}      
/////////////////////////////////////////////////////////////////////////////

//File.h
/////////////////////////////////////////////////////////////////////////////

class DATASOURCE
{
  public:
    int ds_icon;
            CString ds_filename;
   
};

typedef CTypedPtrList<CPtrList, DATASOURCE*> CMyStructList;


class CFileView : public CView
{
  public:      

    BOOL CFileView::AddFile();

    CMyStructList m_DataSourceArray;

};
/////////////////////////////////////////////////////////////////////////////

0
Comment
Question by:cmarsh
[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 Comments
 
LVL 1

Accepted Solution

by:
IgorGrebnev earned 100 total points
ID: 1308364
Most probably you did forget to
#include <afxtempl.h>
Applicaiton Wizard by default does't include this header. Include it in you stdafx.h
By the way you can write straightforward
CTypedPtrList<CPtrList, DATASOURCE*> m_DataSourceArray;
in declaration of you class without prior typedefinition of CMyStructList.
0
 

Author Comment

by:cmarsh
ID: 1308365
You've made me a happy man - it's been bugging me for a couple of weeks now.  Thanks.
0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 73
Pressing cancel button with C# UI Automation 3 101
move a line in eclipse 3 111
Bartender label printing - switch on and off graphics 3 92
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

738 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