, , , , . , - :
void instantiation()
{
Foo<int> f;
f;
}
Foo<int>* instantiation()
{
Foo<int> *p = new Foo<int>();
return p;
}
, :
template <typename T>
class Foo
{
public:
Foo( T const & value );
void set( T const & );
private:
T value_;
};
template <typename T>
Foo<T>::Foo<T>( T const & value ) : value_(value) {}
template <typename T>
void Foo<T>::set( T const & v )
{
value_ = value;
}
template class Foo<int>;
template class Foo<double>;
#include "header.h"
int main()
{
Foo<int> f(5);
f.set( 7 );
Foo<char> f2;
}
, , . , .
: , , .
++ , . ( void f() { }, ), . , . [1], (std::vector:: push_back() std::vector push_back)
"" , , , , , , . , , STL, , .
gcc 4.2 gcc linux , , . (gcc- linux , 4.2, , 4.3 4.4 alredy ), , "" / .
ODR, . , . , ( , ): , (virtual/const-ness...) , () .
[1] , :
template <typename T>
struct Test
{
void f() { std::cout << "f()" << std::endl; }
void g() { std::cout << "g()" << std::endl; }
};
int main()
{
Test<int> t;
t.f();
}