Jump to content
  • Advertisement
Sign in to follow this  
dcosborn

using declaration access with templates

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

Why is it that the using declaration maintains the protected access of v...
struct B
{
	protected:
	int v[3];
};
struct D : B
{
	protected:
	using B::v;
};
int main()
{
	D d;
	d.v[0] = 0;
	return 0;
}

...but as soon as I add templates...
template <typename T> struct B
{
	protected:
	T v[3];
};
template <typename T> struct D : B<T>
{
	protected:
	using B<T>::v;
};
int main()
{
	D<int> d;
	d.v[0] = 0;
	return 0;
}

...v becomes publicly accessible? I would think that the use of templates wouldn't affect the semantics of the using declaration. My compiler is G++ 4.1.1.

Share this post


Link to post
Share on other sites
Advertisement
1>Compiling...
1>main.cpp
1>.\main.cpp(14) : error C2248: 'D<T>::v' : cannot access protected member declared in class 'D<T>'
1> with
1> [
1> T=int
1> ]
1> .\main.cpp(9) : see declaration of 'D<T>::v'
1> with
1> [
1> T=int
1> ]


Visual Studio 2005 Standard

Quote:
Original post by myself, concieted poster that I am, in another thread replying to the open ended of question of why C++ sucks:

There is no 100% conformant C++ compiler. Except maybe Comcaeu, but I expect that's still only like 99.9%. You're not only managing C++'s idiocyncacies, but you're managing multiple compiler's idiocyncracies with each other.

Share this post


Link to post
Share on other sites
Quote:
Original post by dcosborn
Cool, maybe I found a bug then. Thanks for testing.


Maybe. If you havn't tried that exact code yourself, it's worth mentioning that errors from templates typically arn't generated until they're actually instantiated. So if it's another template that's trying to use D<T>::v, make sure that other template is actually getting used/called/instantiated.

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!