Skip to main content
GameDev.net gamedev.net
🔒 Locked

using declaration access with templates

Started by dcosborn Oct 14, 2006 at 12:53 PM 3 replies 1.3k views
Original Post
dcosborn
dcosborn
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.
MaulingMonkey
MaulingMonkey
1>Compiling...1>main.cpp1>.\main.cpp(14) : error C2248: 'D<T>::v' : cannot access protected member declared in class 'D<T>'1>        with1>        [1>            T=int1>        ]1>        .\main.cpp(9) : see declaration of 'D<T>::v'1>        with1>        [1>            T=int1>        ]


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.
dcosborn
dcosborn
Cool, maybe I found a bug then. Thanks for testing.
MaulingMonkey
MaulingMonkey
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::v, make sure that other template is actually getting used/called/instantiated.
dcosborn
dcosborn
Nope its the exact code I posted. Submitted! Hopefully I did it right; first bug report and all.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.