• Advertisement
Sign in to follow this  

sizeof static member of template class

This topic is 3994 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

Hi, I got a problem. I try to do something like this.
struct Foo
{
	const char *anything;
};

class Test2
{
public:
	static Foo aFoo2[];
};

Foo Test2::aFoo2[] = 
{
	{ "1" },
	{ "2" },	
};


int main()
{
	int size = sizeof( Test2::aFoo2 );
}

but on template class. I've tried code like below but it giving "illegal sizeof operand" error.
struct Foo
{
	const char *anything;
};

template<class T>
class Test
{
public:
	static Foo aFoo[];
};

template<class T>
Foo Test<T>::aFoo[] =
{
	{ "1" },
	{ "2" },
};

int main()
{
	int sizeT = sizeof( Test<int>::aFoo ); //	error
}


Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Compiles fine here (gcc 4.1.2). Your compiler might be broken :|

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement