M
marco
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
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