public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ question template resolve pointer through non-templated base  class
@ 2010-03-30 17:36 RusMor
  2010-04-02 13:46 ` andre maute
  0 siblings, 1 reply; 2+ messages in thread
From: RusMor @ 2010-03-30 17:36 UTC (permalink / raw)
  To: gcc-help


  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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: C++ question template resolve pointer through non-templated base  class
  2010-03-30 17:36 C++ question template resolve pointer through non-templated base class RusMor
@ 2010-04-02 13:46 ` andre maute
  0 siblings, 0 replies; 2+ messages in thread
From: andre maute @ 2010-04-02 13:46 UTC (permalink / raw)
  To: gcc-help

Comeau C++ compiles your Code without the A:: prefixes.
Perhaps you need a syntax lawyer here.



In general,
remove the ";" at the end of the curly braces "}" of the function defintions.



On Tuesday 30 March 2010, RusMor wrote:
>   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






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-04-02 13:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-30 17:36 C++ question template resolve pointer through non-templated base class RusMor
2010-04-02 13:46 ` andre maute

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).