Solved

Template problem using Object Pointer List

Posted on 1997-10-18
2
279 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
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

Industry Leaders: 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
Pressing cancel button with C# UI Automation 3 90
NotAlone Challenge 20 88
EvenOdd challenge 10 144
Authenticate using sesu from script 7 109
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

763 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