473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with inheritance and tamplates

The following won't compile under Comeau in strict mode, nor under MS
Whidbey beta in ANSI mode. Can anyone tell me why, and which sections of the
ISO standard apply? The error messages from Comeau are:
"ComeauTest.c", line 42: error: identifier "bar" is undefined

return arg->foo() == bar() // line 45
^

"ComeauTest.c", line 43: error: identifier "Object" is undefined
&& Object
^

<<'bar()' is a public inherited member of the current class and 'Object' is
a protected inherited member of the current class. If I replace them by
this->bar() and this->Object, the errors go away. The source is:>>
#include <typeinfo> // RTTI header

class _eAnyBase
{
public :
_eAnyBase() {}

virtual const std::type_info& foo() const = 0;
virtual const std::type_info& bar() const = 0;

virtual bool _lEqual(const _eAnyBase* h) const = 0;
};

template <class X >
class _eWrapperBase : public _eAnyBase
{
protected:
X Object;
public :
_eWrapperBase(const X& x) : _eAnyBase (), Object(x) {}

const std::type_info& foo() const
{
return typeid(X);
}
const std::type_info& bar() const
{
return typeid(X);
}
};

template <class X >
class _eStorableWrapperBase : public _eWrapperBase<X >
{
public:
_eStorableWrapperBase(const X& x) : _eWrapperBase<X >(x)
{
}

bool _lEqual(const _eAnyBase *arg) const
{
return arg->foo() == bar()
&& Object
== static_cast<const _eStorableWrapperBase<X >* >(arg)->Object;
}
};

enum Enum2 {red, green, blue};

class _eWrapper : public _eStorableWrapperBase<Enum2>
{ // line 54
public:
_eWrapper(const Enum2 & x) : _eStorableWrapperBase<Enum2>(x) {}
};

<<

Thanks - David

Jul 22 '05 #1
8 1715
Code has not any error in my file 'Test.cpp' under ms vc6 and ms
vs.net. I guess filename '.c' cause the error.

Jul 22 '05 #2
David Crocker wrote in
news:41***********************@news.dial.pipex.com in comp.lang.c++:
The following won't compile under Comeau in strict mode, nor under MS
Whidbey beta in ANSI mode. Can anyone tell me why,
I think this one is now in the FAQ, but anyway the name "bar" in
your code is a template argument dependant name, because its a member
of a base class that is dependent on a template argument.

You need to tell the compiler it is a member name, otherwise it
assumes that bar should be found in an outer scope.

This is part of Two Phase Lookup.

The error occurs when the template body is first parsed, at that time
the compiler doesn't know the template paramiter types, so it doesn't
know the type of the dependant base class or what members that base
class has.
and which sections
of the ISO standard apply?
I'd start at 14.6 (Templates / Name Resolution).
The error messages from Comeau are:
"ComeauTest.c", line 42: error: identifier "bar" is undefined

return arg->foo() == bar() // line 45
^

"ComeauTest.c", line 43: error: identifier "Object" is undefined
&& Object
^

<<'bar()' is a public inherited member of the current class and
'Object' is a protected inherited member of the current class. If I
replace them by this->bar() and this->Object, the errors go away.


HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3
I try to compile code under g++. Unfortunately, can't pass, until it is
modified below:

.......
bool _lEqual(const _eAnyBase *arg) const
{
return arg->foo() == _eWrapperBase<X >::bar() && _eWrapperBase<X
::Object

== static_cast<const _eStorableWrapperBase<X >* >(arg)->Object;
}
.......

( add '_eWrapperBase<X >::' )

Jul 22 '05 #4
"Serock" <s.******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Code has not any error in my file 'Test.cpp' under ms vc6 and ms
vs.net. I guess filename '.c' cause the error.


The error only happens if the compiler is run in strict ISO-conformance
mode. My original filename does end in ".cpp".

David

Jul 22 '05 #5
Rob, thanks for replying.
You need to tell the compiler it is a member name, otherwise it
assumes that bar should be found in an outer scope.

This is part of Two Phase Lookup.

The error occurs when the template body is first parsed, at that time
the compiler doesn't know the template paramiter types, so it doesn't
know the type of the dependant base class or what members that base
class has.
...
I'd start at 14.6 (Templates / Name Resolution).


Clause 14.6.2.3 of the standard does say that the base class scope is not
examined until the class template is instantiated, if the base class depends
on a template parameter. But what I am finding is that the base class scope
is not being examined at all, even when the base class is instantiated. [BTW
the Comeau compiler reports an error even if the template is not
instantiated; the MS compiler only reports the error when the template is
instantiated.]

I didn't find any reference to this problem in the FAQ.

David

Jul 22 '05 #6
"Serock" <s.******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I try to compile code under g++. Unfortunately, can't pass, until it is
modified below:

......
bool _lEqual(const _eAnyBase *arg) const
{
return arg->foo() == _eWrapperBase<X >::bar() && _eWrapperBase<X
::Object

== static_cast<const _eStorableWrapperBase<X >* >(arg)->Object;
}
......

( add '_eWrapperBase<X >::' )


Which version of g++ is that? The original code from which this example was
extracted compiles successfully under g++ 3.3.1.

David

Jul 22 '05 #7
g++ 3.4.2

Jul 22 '05 #8
I didn't find any reference to this problem in the FAQ.


Cancel that last comment - it's in section 34.17.

David

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point...
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
3
by: Morten Aune Lyrstad | last post by:
Hi again! I'm having problems with inheritance. I have a base interface class called IObject. Next I have two other interfaces classes, IControl and ICommandMaster, which derives from IObject. ...
0
by: Bita-kookoo | last post by:
I am having a problem with inheritance for my web solution. Here are the steps I took for a project within C#: -I first created a new class, descended from System.Web.UI.Page. For this...
0
by: Mariano | last post by:
Hi, I have posted a bug of the forms designer that overwrites always the Icon, thus preventing Icon inheritance when you derive from a form. I am trying to overcome this by adding an ImageList in...
9
by: surendran.d | last post by:
hi, can diamond inhertance problem be solved using virtual functions,, or can only be done with scope resolution operators.. is there any other way to solve this problem... Thanks, suri
14
by: dl | last post by:
I have two classes, say A and B, both having a data member 'int n'; private in A, public in B. When I derive class C from both public A and public B, B::n should be visible to C while A::n...
9
by: weird0 | last post by:
How does C++ and C# solve the Diamond problem? With the help of interfaces that is. Can anyone elaborate ....... Regards
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.