Archived

This topic is now archived and is closed to further replies.

bilsa

templates?

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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));

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
Sorry, but I don''t understand your post Sabre

It''s a joke playing with the semantics of the English language - I hadn''t noticed you are from Germany. What I mean is that `export'' is regarded by many as an ill-thought language feature, so while Comeau do support `export'', they do not have very good reasons for doing so.

Share this post


Link to post
Share on other sites
I understood your english but not the logic behind it

[edited by - novum on May 6, 2003 10:49:50 AM]

Share this post


Link to post
Share on other sites
Hey, this is exactly what I was trying to do a couple days ago. Then I couldn''t solve the problem, but now I know

Share this post


Link to post
Share on other sites