Link to home
Start Free TrialLog in
Avatar of cmarsh
cmarsh

asked on

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;

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

ASKER CERTIFIED SOLUTION
Avatar of IgorGrebnev
IgorGrebnev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmarsh
cmarsh

ASKER

You've made me a happy man - it's been bugging me for a couple of weeks now.  Thanks.