J
Javier Montoya
Hi everybody!
I've two template classes, say Bar<S> and Foo<T>. Inside of the Foo<T>
I've a method that returns Bar<S>*. After compiling the code, I get an
error of:
error: no matching function for call to
‘CBar<float>::doSomething(int&)’
make: *** [main] Error 1
Does somebody has an idea about how could I solve the problem? Below
the structure of my code:
// bar.h
#ifndef BAR_H
#define BAR_H
template < class S >
class Bar{
....
};
#endif
// bar.cpp
#include <bar.h>
....
....
#include "bar-impl.inc"
// bar-impl.inc
template class Bar<int>;
template class Bar<float>;
// foo.h
#ifndef FOO_H
#define FOO_H
#include <bar.h>
template < class T >
class Foo{
public:
.....
int getSomething(int);
....
template <class BarType>
BarType * doSomething(int);
....
};
#endif
// foo.cpp
#include <foo.h>
.....
template < class T >
template <class BarType>
BarType * Foo<T>::doSomething(int idx){
int num = this->getSomething(idx);
BarType * pBar = new BarType(num);
return pBar;
}
.......
#include "foo-impl.inc"
// foo-impl.inc
template class Foo<int>;
template class Foo<float>;
template Bar<float> * Foo<int>::doSomething(int);
template Bar<float> * Foo<float>::doSomething(int);
// main.cpp
#include <bar.h>
#include <foo.h>
int main(){
Bar<float> * pBar = NULL;
int num=4;
Foo<float> * pFoo = new Foo<float>();
pBar = pFoo->doSomething(num);
return (0);
}
I've two template classes, say Bar<S> and Foo<T>. Inside of the Foo<T>
I've a method that returns Bar<S>*. After compiling the code, I get an
error of:
error: no matching function for call to
‘CBar<float>::doSomething(int&)’
make: *** [main] Error 1
Does somebody has an idea about how could I solve the problem? Below
the structure of my code:
// bar.h
#ifndef BAR_H
#define BAR_H
template < class S >
class Bar{
....
};
#endif
// bar.cpp
#include <bar.h>
....
....
#include "bar-impl.inc"
// bar-impl.inc
template class Bar<int>;
template class Bar<float>;
// foo.h
#ifndef FOO_H
#define FOO_H
#include <bar.h>
template < class T >
class Foo{
public:
.....
int getSomething(int);
....
template <class BarType>
BarType * doSomething(int);
....
};
#endif
// foo.cpp
#include <foo.h>
.....
template < class T >
template <class BarType>
BarType * Foo<T>::doSomething(int idx){
int num = this->getSomething(idx);
BarType * pBar = new BarType(num);
return pBar;
}
.......
#include "foo-impl.inc"
// foo-impl.inc
template class Foo<int>;
template class Foo<float>;
template Bar<float> * Foo<int>::doSomething(int);
template Bar<float> * Foo<float>::doSomething(int);
// main.cpp
#include <bar.h>
#include <foo.h>
int main(){
Bar<float> * pBar = NULL;
int num=4;
Foo<float> * pFoo = new Foo<float>();
pBar = pFoo->doSomething(num);
return (0);
}