#### Archived

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

# 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.

## 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 on other sites
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 on other sites
You need a space between the two > > signs.

##### 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 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 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 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]

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 48
• ### Forum Statistics

• Total Topics
632637
• Total Posts
3007577
• ### Who's Online (See full list)

There are no registered users currently online

×