This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ question template resolve pointer through non-templated base class


  Dear reader,

  I have a question  about an interesting feature of gcc (version etc. see
below).

  The "problem" is demonstrated with this minimal code:

#include <iostream>
#include <vector>

using namespace std;

class A
{
public:
  template <typename AType> void Fun () {};
};

class Base
{
public:
  A * GetA() { return new A; };
};

class DerivedNotTemplated : public Base
{
public:
  void Fun ()
  {
    this->GetA()->/*A::*/Fun<int>();  // Don't need the A:: here
  };
};

template <typename BType>
class DerivedTemplated : public Base
{
public:
  void Fun ()
  {
    this->GetA()->A::Fun<BType>();   // Why need the "A::" ??
  };
};

int main ()
{
  return 1;
};

  If I omit the "A::" in the definition of DerivedTemplated<BType>::Fun(), I
get the following compiler error:

ytsen@moniac:~/scratch> g++ test.templated.templated.C
test.templated.templated.C: In member function âvoid
DerivedTemplated<BType>::Fun()â:
test.templated.templated.C:35: error: expected primary-expression before â>â
token
test.templated.templated.C:35: error: expected primary-expression before â)â
token

  But in the non-templated case this does not happen. My question is "why"
??

  Many thanks in advance!!

  Cheers,

Ytsen.
















ytsen@moniac:~/scratch> gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.4
--enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/
--with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap
--with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.4
--enable-linux-futex --without-system-libunwind --with-arch-32=i586
--with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.4.1 [gcc-4_4-branch revision 150839] (SUSE Linux) 
ytsen@moniac:~/scratch> uname -a
Linux moniac 2.6.31.8-0.1-desktop #1 SMP PREEMPT 2009-12-15 23:55:40 +0100
x86_64 x86_64 x86_64 GNU/Linux

-- 
View this message in context: http://old.nabble.com/C%2B%2B-question-template-resolve-pointer-through-non-templated-base-class-tp28080960p28080960.html
Sent from the gcc - Help mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]