Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Scope visibility

Reply
Thread Tools

Scope visibility

 
 
Kaba
Guest
Posts: n/a
 
      03-13-2006
Why doesn't the following work?

template <typename Type>
class A
{
public:
Type data_;
};

template <typename Type>
class B: public A<Type>
{
public:
void set()
{
data_ = 4;
}
};

int main()
{
B<int> b;
b.set();
return 0;
}

If you declare "using A<Type>::data_;" then it works. If you use normal
classes, this works without "using". I don't get it. Tested with
msvc2005 and comeau. Words from the standard?

--
Kalle Rutanen
http://kaba.hilvi.org
 
Reply With Quote
 
 
 
 
Steve
Guest
Posts: n/a
 
      03-13-2006
On 13/3/06 22:43, in article http://www.velocityreviews.com/forums/(E-Mail Removed),
"Kaba" <(E-Mail Removed)> wrote:

> Why doesn't the following work?
>
> template <typename Type>
> class A
> {
> public:
> Type data_;
> };
>
> template <typename Type>
> class B: public A<Type>
> {
> public:
> void set()
> {
> data_ = 4;
> }
> };
>
> int main()
> {
> B<int> b;
> b.set();
> return 0;
> }
>
> If you declare "using A<Type>::data_;" then it works.


But do you understand why that works?

> If you use normal
> classes, this works without "using". I don't get it. Tested with
> msvc2005 and comeau. Words from the standard?


At the risk of doing your homework for you, have a read of

<http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18>

Apart from your example using a member variable and the example in the FAQ
using a member function, they're both remarkably similar!

--
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

 
Reply With Quote
 
 
 
 
Kaba
Guest
Posts: n/a
 
      03-13-2006
> > If you declare "using A<Type>::data_;" then it works.
>
> But do you understand why that works?
>
> > If you use normal
> > classes, this works without "using". I don't get it. Tested with
> > msvc2005 and comeau. Words from the standard?

>
> At the risk of doing your homework for you, have a read of
>
> <http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18>
>
> Apart from your example using a member variable and the example in the FAQ
> using a member function, they're both remarkably similar!


Thank you Steve, this answered my question. No this is not homework, I
just found and switched off the "language extensions" option in visual
studio and got errors I had not seen before

--
Kalle Rutanen
http://kaba.hilvi.org
 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      03-14-2006
In article <(E-Mail Removed)>,
Kaba <(E-Mail Removed)> wrote:
>Why doesn't the following work?
>
>template <typename Type>
>class A
>{
>public:
>Type data_;
>};
>
>template <typename Type>
>class B: public A<Type>
>{
>public:
>void set()
>{
>data_ = 4;
>}
>};
>
>int main()
>{
>B<int> b;
>b.set();
>return 0;
>}
>
>If you declare "using A<Type>::data_;" then it works. If you use normal
>classes, this works without "using". I don't get it. Tested with
>msvc2005 and comeau. Words from the standard?


Have a look at
http://www.comeaucomputing.com/techt...membernotfound
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visibility vs Scope goodbadwolf C++ 8 03-25-2008 10:22 AM
visibility, declarative region, scope, validity, introduction and accessibility Steven T. Hatton C++ 1 12-13-2006 06:29 AM
Variable Scope / Visibility / Caching Problem Steve Wark ASP .Net 1 05-23-2005 12:36 PM
Variable Scope / Visibility Steve Wark ASP .Net 0 05-23-2005 12:00 PM
Is "scope" different from "visibility" ? TTroy C Programming 8 02-14-2005 09:46 AM



Advertisments