templates?

Started by
12 comments, last by bilsa 20 years, 11 months ago
Hi! I was thinking of having a function that takes an unknown variable, so this is what I have tried:
  
class cMeshObject
{
public:
	cMeshObject();
	~cMeshObject();

	template <class VERTEX_STRUCT>
	int Create(VERTEX_STRUCT *mesh_vertices, int size_t);

	int Draw();
};

//This is how the description looks:


template <class VERTEX_STRUCT>
cMeshObject::Create(VERTEX_STRUCT *mesh_vertices, int size_t);
{
//..

}

  
Unfortunately I get an unresolved external error
  
error LNK2001: unresolved external symbol "public: int __thiscall cMeshObject::Create(struct s3DVERTEXTEX *,int)" (?Create@cMeshObject@@QAEHPAUs3DVERTEXTEX@@H@Z)
.\Debug/WindowShell.exe : fatal error LNK1120: 1 unresolved externals
  
Could anyone help me out with this and correct my mistake? thx!
Advertisement
Sorry for the double post!
Delete either, or edit one of the original posts to include a link to the other.
forgot to show how I call the function:

  //s3DVERTEX is a structure I have made...s3DVERTEX my_vertices[] = {{1.0f, 1.0f, 1.0f, D3DCOLOR_RGBA(255,255,255,255)}};cMeshObject *mesh = new cMeshObject();mesh->Create(my_vertices, sizeof(my_vertices));  
You have to declare templates in the header
quote:Original post by bilsa
//This is how the description looks:

The implementation of the template needs to be visible to the compiler from the instantiation point, which in plain English means you should put the function definition into the header file.

[edited by - SabreMan on May 6, 2003 9:23:19 AM]
ok

[edited by - bilsa on May 6, 2003 9:43:25 AM]
Ok, It worked allright when I put the description of the function inside my class in the header file.

But if I would want to have the description of my function in another file, then how would I do?

I want to have it like this:

int cMeshObject::Create(VERTEX_TEMPLATE *my_vertices, int size_t)
{
//...
}

cuz the way it is now, my class looks enourmous and is hard to read...
You can put it outside of the class definition, but not outside of the header

There's the keyword "export" which would allow what you want, but only Comeau C++ supports it and the other compilers don't support it for very good reasons

[edited by - novum on May 6, 2003 10:09:07 AM]
quote:Original post by noVum
There''s the keyword "export" which would allow what you want, but only Comeau C++ supports it and the other compilers don''t support it for very good reasons

Comeau doesn''t support export for very good reasons either. Comeau just supports export.

This topic is closed to new replies.

Advertisement