Skip to main content
gamedev.net
🔒 Locked

Nesting templates

Started by Paul Dolhai Jun 17, 2002 at 1:25 PM 4 replies 1k views
Original Post
Paul Dolhai
Paul Dolhai
I''m having some trouble getting my manager template to work with the stl vectors. I''m getting errors in memory.h and new.h. Stuff like.. syntax error : ''constant'' c:\program files\microsoft visual studio\vc98\include\new(35) : error C2091: function returns function error C2809: ''operator new'' has no formal parameters error C2059: syntax error : ''constant'' error C2091: function returns function error C2556: ''void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)'' : overloaded function differs only by return type from ''void *(__cdecl *__cdecl op I''m by no means an expert with templates or stl so my problem may be easy to spot..but I don''t know what it is. Here''s the my declaration.. #include <vector> using namespace std; template class CTManager { typedef vector OBJECTVECTOR; typedef OBJECTVECTOR::iterator ObjectVectItor; public: CTManager(void); ~CTManager(void); int Add(const T p_T); int Delete(const T p_T); int Delete(int index); int DeleteAll(); T Get(int index); T Get(const T p_T); int GetCount(); protected: int error; OBJECTVECTOR p_T; }; Thanks Paul
Fruny
Fruny
Relevant defects in VC++ : #1 and #2

Beyond that, it would help to see the code causing the bug (your call to new).

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on June 17, 2002 2:37:50 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Paul Dolhai
Paul Dolhai
The manager is declared like this

CVisualisationManager* m_VisualisationManager;
m_VisualisationManager = new CVisualisationManager;

if you meant the objects being inserted they''re newed like this

CVisualisationObject* newObject=NULL;

newObject=new CGraphicObject;
if (newObject)
Add(newObject);

Hope this helps...

Paul

merowe
merowe
Try this:

Class declaration:

#include <vector>

using namespace std;

template < class T > // <- Added
class CTManager // <- Changed
{
typedef vector OBJECTVECTOR;
typedef OBJECTVECTOR::iterator ObjectVectItor;

public:
CTManager(void);
~CTManager(void);

int Add(const T p_T);
int Delete(const T p_T);
int Delete(int index);
int DeleteAll();

T Get(int index);
T Get(const T p_T);

int GetCount();

protected:
int error;
OBJECTVECTOR p_T;
};

When instanciating:

CVisualisationManager< CType >* m_VisualisationManager;
m_VisualisationManager< CType > = new CVisualisationManager< CType >;

where CType is the what you want T to be replaced with in the class declaration.

Note: I put spaces between the C/C++ identifier and the <> brackets because the forum is looking at that code as a tag identifier..

[edited by - merowe on June 17, 2002 2:56:40 PM]
Paul Dolhai
Paul Dolhai
Thanks...I think that fixed some errors but I still have some that I always did...
these are from new.h and I have 3 sets of the same errors.
error C2059: syntax error : ''constant''
error C2091: function returns function
error C2809: ''operator new'' has no formal parameters
error C2059: syntax error : ''constant''
error C2091: function returns function
error C2556: ''void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)'' : overloaded function differs only by return type from ''void *(__cdecl *__cdecl op

These are from memory.h
error C2065: ''_P'' : undeclared identifier
(16) : error C2059: syntax error : ''constant''
(17) : error C2091: function returns function
(17) : error C2784: ''void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257''> &)'' : could not deduce template argument for ''void *(__cdecl *)(u
nsigned int,class std::allocator<_Ty> &)'' from ''void *(__cdecl *)(unsigned int)''
(20) : error C2954: template definitions cannot nest

I''ve looked at the examples of the errors but I can''t get anything from my code because these errors appear to occur in the header files..

Paul
Paul Dolhai
Paul Dolhai
These errors happen when you don''t include vector and the using namespace in your other files...DOH!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.