I have a problem using template and typedef, someone can tell me what is wrong !

From: marco (marco_cecchetti_at_tin.it)
Date: 08/31/04


Date: Tue, 31 Aug 2004 18:44:02 GMT


the problem:

I use a typedef inside a class template, than I use this type
(dim_v<N1>::Type) to define the argument of a template function f
but when I call this function from main, the compiler (gcc 3.4.1)
tell me: "no matching function found".
If someone, more expert than me, could tell me what is wrong
I would be very happy

the code:

===============================================================
file: scratch.h
---------------------------------------------------------------

#include <iostream>

typedef int dim_t;
typedef unsigned int rank_t;

template<typename T, rank_t N>
class V
{
       private :
       T dm1;
       rank_t dm2;

       public :
       V(T p1, rank_t p2) :
           dm1(p1), dm2(p2+N)
       {
       }

       rank_t get_2()
       {
           return dm2;
       }
};

template<rank_t N1>
class dim_v
{
       public :
       typedef V<dim_t, N1> Type;
};

template<rank_t P>
void f(typename dim_v<P>::Type v)
{
       std::cout << std::endl << v.get_2() << std::endl;
}

===============================================================

===============================================================
file: main.cpp
---------------------------------------------------------------

#include "scratch.h"

int main( int argc, char * argv[] )
{
      dim_t type = 5;
      rank_t val = 10;
      const rank_t r = 3;
      dim_v<r>::Type v(type, val); // OK
      f(v); // ERROR !

      return 0;
}

===============================================================

# compile command :
g++ -c -o /mnt/TEMP/cpp_projects/SymbolArray/linux/Debug_Build/main.o -g2
-O0 -MD -I/usr/include -I/usr/local/include -I/usr/include/c++/3.4.1
main.cpp

# compile output :
main.cpp: In function `int main(int, char**)':
"main.cpp": main.cpp error: no matching function for call to `f(V<dim_t,
3u>&)' at line 111
GNU C++ Compiler exited with error code: 1

# compiler version :
gcc 3.4.1 (I get the same error also with version 3.3.2)

# machine :
processor: amd athlonxp 1700+
memory: 512MB
os: linux mandrake 10.0

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


Relevant Pages

  • Re: Tcl_CreateCommand in 8.4.4
    ... Tcl_CmdProc typedef is now a bit different. ... typedef int _ANSI_ARGS_((ClientData clientData, ... This way the compiler complains SomeCmd sig ...
    (comp.lang.tcl)
  • Re: Fooling C Compiler
    ... I tried using typedef. ... Is there a possibility to fool your doctor ... I assume "fooling the compiler" was meant to be ...
    (comp.lang.c)
  • Re: data types
    ... ...but the manual for the compiler I am using says int is 16-bit. ... typedef [whatever type is 16 bits in your platform] int16; ...
    (comp.lang.c)
  • Re: I would appreciate some help with template overloading
    ... typedef uint16_t doublebyte; ... If you prefix that with a declaration of said class template: ... but I don't know if it's usable) so the code that compiler ... Visual Studio or DevC++, both feature a good compiler with an IDE. ...
    (microsoft.public.vc.language)
  • Re: VS2005 doesnt like its own suggestions
    ... When I typedef in my program, it has an effect ONLY on me. ... You are never forced to use INT. ... but use a different compiler such as CodeWarrior or Borland. ... There is no language changes here. ...
    (microsoft.public.vc.language)