N
Ney André de Mello Zunino
Hello.
I'm trying to use that template specialization "trick" to allow one to
keep template implementations separate from the header file. However, I
am having trouble with the right syntax --I get a linker error when I
try to instantiate a Foo<int> on main(). Could anybody help?
// ======================== Foo.h ========================
#ifndef FOO_H__
#define FOO_H__
template<typename Type>
class Foo {
public:
Foo(Type object);
};
#endif
// =======================================================
// ======================= Foo.cpp =======================
#include "Foo.h"
#include <iostream>
template<typename Type>
Foo<Type>::Foo(Type object) {
std::cout << "Building Foo with object: " << object << "\n";
}
template<> Foo<int>::Foo(int);
// =======================================================
// ====================== Main.cpp =======================
#include "Foo.h"
int main() {
Foo<int> foo(10);
}
// =======================================================
Thank you,
I'm trying to use that template specialization "trick" to allow one to
keep template implementations separate from the header file. However, I
am having trouble with the right syntax --I get a linker error when I
try to instantiate a Foo<int> on main(). Could anybody help?
// ======================== Foo.h ========================
#ifndef FOO_H__
#define FOO_H__
template<typename Type>
class Foo {
public:
Foo(Type object);
};
#endif
// =======================================================
// ======================= Foo.cpp =======================
#include "Foo.h"
#include <iostream>
template<typename Type>
Foo<Type>::Foo(Type object) {
std::cout << "Building Foo with object: " << object << "\n";
}
template<> Foo<int>::Foo(int);
// =======================================================
// ====================== Main.cpp =======================
#include "Foo.h"
int main() {
Foo<int> foo(10);
}
// =======================================================
Thank you,