• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Template problem using Object Pointer List

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
cmarsh
Asked:
cmarsh
1 Solution
 
IgorGrebnevCommented:
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
 
cmarshAuthor Commented:
You've made me a happy man - it's been bugging me for a couple of weeks now.  Thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now