Re: XCode 3.0 header/scope/namespace issues, gcc 4.0 bug?
Re: XCode 3.0 header/scope/namespace issues, gcc 4.0 bug?
- Subject: Re: XCode 3.0 header/scope/namespace issues, gcc 4.0 bug?
- From: Jeff DuMonthier <email@hidden>
- Date: Mon, 26 Nov 2007 08:11:54 -0500
I did a little more experimenting and found that a using clause can
allow access to inherited members in a template class without explicit
scoping. That will dramatically reduce the amount of editing
necessary to fix things if I have to, but I still find it hard to
believe this is correct behavior.
Here is the code example again comparing the behavior of class vs.
template class and showing both workarounds. As shown this will
result in one compiler error in tc2::getI() because the template
class's inherited data member not it scope unless the scope is
specified explicitly. Uncommenting the using clause in the
declaration of tc2 will allow access without explicit scoping and
eliminate the error.
*******************
// define a class with an integer data member
class c1
{
public:
int i1;
};
// define a subclass which accesses the inhereted integer data member
class c2 : public c1
{
public:
int getI();
};
int c2::getI()
{
int i = i1;
return i;
}
// define a template class with an integer data member
template<typename tt>
class tc1
{
public:
tt t1;
int i1;
};
// define a template subclass which accesses the inherited integer
data member
template<typename tt>
class tc2 : public tc1<tt>
{
public:
// using tc1<tt>::i1; // Needed to allow access to inherited
data member i1 without explicit scoping
int getI();
};
template<typename tt>
int tc2<tt>::getI()
{
int i = tc1<tt>::i1; // this always works
i = i1; // without the using clause this causes a
compiler error: 'i1' was not declared in this scope
return i;
}
// force instantiation of template classes and methods
int test()
{
c2 theC2;
tc2<int> theTC2;
int ic = theC2.getI();
int itc = theTC2.getI();
return ic + itc;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden