Solved

Template problem using Object Pointer List

Posted on 1997-10-18
2
255 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
2 Comments
 
LVL 1

Accepted Solution

by:
IgorGrebnev earned 100 total points
Comment Utility
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
Comment Utility
You've made me a happy man - it's been bugging me for a couple of weeks now.  Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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