Skip to main content
gamedev.net
🔒 Locked

g++ templated function bug problem

Started by deffer Apr 14, 2005 at 3:01 AM 0 replies 550+ views
Original Post
deffer
deffer
Hi again. So I've got this problem with g++(gcc as well), that I've found out some people are saying is considered as it's bug. Here it goes:

template< typename T >
class A
{
public:
  template< typename Ta >
  void funcA(void) {
    // something (probably consisting of Ta usage).
  }
public:
  // ...
};

template< typename T >
class B
{
public:
  A<int> m_a;
public:
  void callA(void) {
    m_a.funcA<double>; // g++ says: parse error before ';' token.
  }
};

int main()
{
  B b;
  b.callA();
  // ...
}


I've seen several discussionss about this. A hacky(and very dirty) solution, that someone came up with, was to add an additional parameter to the templated function, that relies on the template argument. Then, whe calling, ignore template argument, and just pass the fake one, in hope the compiler deduces what the template param actually is.

template< typename T >
struct dummy {};

// Declare with:
template< typename T >
void funcA(dummy<T> fakeParam) { /*...*/ };

// And call with:
a.funcA(dummy<double>);
// Here compiler should deduce the template parameter.
// And not brag about being too stupid to understand the grammatic.


The conclusion: It did worked for some simple examples, but failed for a more complicated one. So the question is: Is it possible to do it at all? Is there a better version of gxx, where this bug is not present (I'm using 3.3.4)? Finally, can I use any another compliler (the program should run under linux)? Help... /def
MaulingMonkey
MaulingMonkey
Quote:
Original post by deffer
Is there a better version of gxx, where this bug is not present (I'm using 3.3.4)?


Yes. On my linux box:

panda@industry:~$ g++ --versiong++ (GCC) 3.3.5 (Debian 1:3.3.5-8)Copyright (C) 2003 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


That's after a fairly recent upgrade - but that's only the stable branch (by which I mean Debian stable, not GCC stable). According to the Free Software Foundation, GCC is up to 3.4.3 (GCC stable).

Quote:
Finally, can I use any another compliler (the program should run under linux)?


Yes. For example, Intel has a C++ compiler that will generate C++ code (optimized for intel processors) on Linux - you can download it free for noncommercial purpouses. See here (8.1, which I believe is the latest).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.