Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > templates and i...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 4131 of 4262
Post > Topic >>

templates and inheritance

by ruebezaehler <ruebezaehler@[EMAIL PROTECTED] > Apr 30, 2008 at 05:36 PM

Hello,

I have two cl*****, C_A and template<typename T>C_B which are derived 
"private" from the base cl***** C_A_ resp. template<typename T>C_B_. 

The behaviour is quite different. The users of C_B can access the 
variable var of C_B_, but not the users of C_A. Moreover, in C_A the 
visibility of var is also controlable via the construct "private: / 
public: using C_A_::var;", but this is not the case for C_B.

Can sb. explain the different behaviour. 

I'm using the g++ Version 4.1.3.

class C_A_
	{
	public:
		int var;
		virtual ~C_A_( void ){}
	};

class C_A : private C_A_
	{
	private:
		using C_A_::var;
	public:
		C_A( void ){} 
		virtual ~C_A(void) {}
	};


template<typename T>
class C_B_
	{
	public:
		T var;
		virtual ~C_B_( void ){}
	};

template<typename T>
class C_B : private C_B_<T>
	{
	private:
		using C_B_<T>::var;
	public:
		C_B( void ){} 
		virtual ~C_B(void) {}
	};
	
 
int main(int argc, char* argv[]) 
	{
	C_B<int> 	oB;
	oB.var = 5;// no error from the compiler
		
	C_A		oA;
	oA.var	= 5;// error: »int C_A_::var« is not accessible
	
	return 0;
	}//
 




 4 Posts in Topic:
templates and inheritance
ruebezaehler <ruebezae  2008-04-30 17:36:25 
Re: templates and inheritance
"sk_usenet" <  2008-04-30 10:01:43 
Re: templates and inheritance
Bart van Ingen Schenau &l  2008-04-30 22:16:49 
Re: templates and inheritance
ruebezaehler <ruebezae  2008-05-01 08:54:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 22:46:31 CDT 2008.