Jump to content
  • Advertisement

Archived

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

Grizwald

Nested C++ templates: Is it possible?

This topic is 5223 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I''m working on a flexible vertex format system for my engine, and I am just dicking around with some templates (the project isn''t serious, so don''t get on my case about efficiency. a vertex with a single pos entry would be declared as such: VERTEX_BEGIN> my_vertex; here are the structure definitions:
template <class arg>
struct VERTEX_BEGIN : arg
{
	long FVF;
	VERTEX_BEGIN()
	{
		FVF = 0;
		super();
	}
};

template <class arg>
struct VERTEX_POS : arg
{
	D3DXVECTOR3 pos;
	VERTEX_POS()
	{
		FVF = FVF | D3DFVF_XYZ;
		super();
	}
};

struct VERTEX_END
{
	//NOTHIN

};
as you can see, the template arguements define parent classes. Now as long as I don''t define a vertex, these classes will compile. but if I try to define my_vertex as a VERTEX_BEGIN>, I get the following errors: d:\Source Code\Isis\Isis\Direct3DRenderer.cpp(13): error C2947: expecting ''>'' to terminate template-argument-list, found ''>>'' d:\Source Code\Isis\Isis\Direct3DRenderer.cpp(13): error C2146: syntax error : missing '','' before identifier ''my_vertex'' d:\Source Code\Isis\Isis\Direct3DRenderer.cpp(13): error C2065: ''my_vertex'' : undeclared identifier d:\Source Code\Isis\Isis\Direct3DRenderer.cpp(13): error C2143: syntax error : missing ''>'' before '';'' d:\Source Code\Isis\Isis\Direct3DRenderer.cpp(13): error C2976: ''VERTEX_BEGIN'' : too few template arguments thats about all i can give ya at the moment. Any help would be greatly appreciated. Thanky

Share this post


Link to post
Share on other sites
Advertisement
Your post is a little hard to understand completely. Are you doing this?


VERTEX_BEGIN<VERTEX_POS<SomeClassName>> MyVertex;


what are you using to declare your variable?

Share this post


Link to post
Share on other sites
you have you put a space between your two end template greater than signs otherwise it will be interpreted as the right shift operator.


VERTEX_BEGIN<VERTEX_POS<VERTEX_END> > my_vertex; // note the space


/* usually I put spaces always before
the end template greater than sign
and after the opening one just to
make it look more balanced as well */


VERTEX_BEGIN< VERTEX_POS< VERTEX_END > > my_vertex2;

Share this post


Link to post
Share on other sites
thanks, I knew it was something like that

I also had the order screwed up

template <class arg>
struct VERTEX_BEGIN : arg
{

};

template <class arg>
struct VERTEX_POS : public arg
{
D3DXVECTOR3 pos;
VERTEX_POS()
{
FVF = FVF | D3DFVF_XYZ;
}
};


struct VERTEX_END
{
long FVF;
VERTEX_END()
{
FVF = 0;
}
};

is what i should have.

now I need to get these working with direct3d

Share this post


Link to post
Share on other sites
And also, I can''t have the FVF member IN the class, because it messed up how Direct3D likes its FVFs. How can I make it so FVF isn''t in the class, but there is a unique one for every vertex (it is being modified by all the ctors.

thanks again

Share this post


Link to post
Share on other sites
quote:
Original post by Grizwald
And also, I can't have the FVF member IN the class, because it messed up how Direct3D likes its FVFs. How can I make it so FVF isn't in the class, but there is a unique one for every vertex (it is being modified by all the ctors.

thanks again

You can compute the FVF, IIRC. <-- No it was the otherway around.

You CAN put the FVF in the begin structure, and let each derived class add a flag.


--
You're Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net's DirectX FAQ. (not as cool as the Graphics and Theory FAQ)


[edited by - Pipo DeClown on June 7, 2004 6:12:37 AM]

[edited by - Pipo DeClown on June 7, 2004 6:13:38 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!