[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Help with explicit instantiation
From: |
E. Robert Tisdale |
Subject: |
Help with explicit instantiation |
Date: |
Fri, 17 Sep 2004 20:51:08 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803 |
> cat X.h
#ifndef GUARD_X_H
#define GUARD_X_H 1
#include <iostream>
template<class T>
class X {
private:
// representation
T D;
public:
// functions
T data(void) const { return D; }
// constructors
X(T d = 0): D(d) { }
X(const X& x);
template<class S>
X(const X<S>& x);
friend
std::ostream& operator<<(
std::ostream& os, const X<T>& x) {
return os << x.data();
}
};
#endif//GUARD_X_H 1
> cat X.cc
#include "X.h"
template<class T>
X<T>::X(const X& x): D(x.D) {
std::cerr << "copy constructor" << std::endl;
}
template<class T>
template<class S>
X<T>::X(const X<S>& x): D(x.data()) {
std::cerr << "conversion constructor" << std::endl;
}
template X<float>::X(const X<int>& x);
template X<float>::X(const X<float>& x);
> g++ -Wall -ansi -pedantic -c X.cc
X.cc:15: error: ambiguous template specialization `X<>' \
for `X<float>::X(const X<float>&)'
X.cc:4: error: candidates are: \
X<T>::X(const X<T>&) [with T = float]
X.h:17: error: \
template<class S> X::X(const X<S>&) [with S = S, T = float]
What did I do wrong?
- Help with explicit instantiation,
E. Robert Tisdale <=