OONumerics User :

From: Julian Cummings (cummings_at_[hidden])
Date: 2006-03-27 19:27:00


This has to do with proper enforcement of the C++ standard. One of the
namespace resolution rules is that if a class derives from a templated base
class, the namespace of that templated base class is not examined when
resolving a symbol unless it is clearly dependent on the template parameter.
(I am simplifying and paraphrasing the C++ standard here.) So if the
compiler is properly enforcing the namespace lookup rules (as gcc began
doing fairly recently), it will not find the base class members that are
being referenced in your example. You can prefix them with the this->
pointer to tell the compiler explicitly where to look. Another solution is
to use a using declaration to bring the base class items into the scope of
the derived class. I tend to prefer this approach, especially in cases
where the base class members are referenced multiple times within the scope
of the derived class. With this approach, you would modify the class C
definition like this:

class C : public B<C>
{
   using B<C>::some_data;
   using B<C>::x;
   using B<C>::y;
   inline float SomeFunc(int i, int j, int k) {
         return some_data[k*x*y + j*x + i];
   }
}

Regards, Julian C.

Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]
 

> -----Original Message-----
> From: oon-list-bounces_at_[hidden]
> [mailto:oon-list-bounces_at_[hidden]] On Behalf Of Hari Sundar
> Sent: Monday, March 27, 2006 2:01 PM
> To: Mike Marchywka
> Cc: oon-list_at_[hidden]
> Subject: Re: [oon-list] Static Polymorphism
>
> I tried it with gcc 4 and 3.4 .. doesn't work with either ...
>
> it does work if I use
>
> this->some_data[k*x*y + j*x + i];
>
> So is this a compiler issue ?
>
> thanks,
> ~Hari
>
> On 3/27/06, Mike Marchywka <mmarchywka_at_[hidden]> wrote:
> >
> >
> > Worked from the cygwin version, at least it tried to link.
> I used to
> > have so many problems with the MS compilers finding stuff
> I gave up on anything fancy.
> > You can google the terms and find mail lists that discuss related
> > issues- I think early on there were lots of problems like this.
> >
> > $ gcc asdf.cpp
> >
> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/../../../libcygwin.a(libcmain.o)
> > :: undefin ed reference to `_WinMain_at_16'
> > collect2: ld returned 1 exit status
> >
> >
> >
> > class A {
> > protected:
> > float * some_data;
> > int x;
> > int y;
> > int z;
> > }
> > ;
> > template <typename T>
> > class B : public A
> > {
> > public:
> > T& asLeaf() { return static_cast<T&>(*this); }
> > inline float SomeFunc(int i, int j, int k) {
> > return asLeaf().SomeFunc(i,j,k);
> > }
> > }
> > ;
> > class C : public B<C>
> > {
> > inline float SomeFunc(int i, int j, int k) {
> > return some_data[k*x*y + j*x + i];
> > }
> > }
> >
> >
> > ;
> >
> >
> >
> >
> **********************************************************************
> > ***
> > Mike Marchywka
> > EyeWonder
> > Instant Streaming, Infinite Results
> >
> > 1447 Peachtree Street
> > 9th Floor
> > Atlanta, GA 30309
> >
> > w.678-891-2033
> > c.
> > h.770-565-8101
> > mmarchywka_at_[hidden]
> > alt: marchywka_at_[hidden]
> > Instant Streaming, Intelligent results.
> >
> **********************************************************************
> > ***
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: oon-list-bounces_at_[hidden]
> [mailto:oon-list-bounces_at_[hidden]]On Behalf Of Hari Sundar
> >
> > Sent: MondayMarch-27-2006 02:33 PM
> > To: oon-list_at_[hidden]
> > Subject: Re: [oon-list] Static Polymorphism
> >
> >
> >
> > Sorry to trouble you all again, but it seems that I
> can't get the Barton-Nackman trick to work. I had problems
> originally, so tried a simple test problem .. which worked,
> but my original problem is not working. My inheritance is
> like this,
> >
> > Class A {
> > protected:
> > float * some_data;
> > int x;
> > int y;
> > int z;
> > }
> >
> > template <typename T>
> > Class B : public A
> > {
> > public:
> > T& asLeaf() { return static_cast<T&>(*this); }
> > inline float SomeFunc(int i, int j, int k) {
> > return asLeaf().SomeFunc(i,j,k);
> > }
> > }
> >
> > class C : public B<C>
> > {
> > inline float SomeFunc(int i, int j, int k) {
> > return some_data[k*x*y + j*x + i];
> > }
> > }
> >
> > When I use gcc to compile this .. I get errors of the sort ..
> >
> > error: 'some_data' was not declared in this scope
> > error: 'x' was not declared in this scope
> > error: 'y' was not declared in this scope
> >
> > Any ideas ?
> >
> > thanks,
> > ~Hari
> >
> >
> >
>
>
>
> --
> ??? ?????????????????? ??? ?? ??? ??? ?? ? ?
> ???????????????? ???? ???????????????? ??? ??? ?? ? ??? ??
>
> Whence all creation had its origin,
> He, whether he fashioned it or whether He did not, He, who
> surveys it all from the highest heaven, He knows - or maybe
> even He does not know.
>
> ~Rg veda
>
> _______________________________________________
> oon-list mailing list
> oon-list_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/oon-list
>