[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with explicit instantiation
From: |
Yevgen Muntyan |
Subject: |
Re: Help with explicit instantiation |
Date: |
Sat, 18 Sep 2004 03:06:33 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040809 |
E. Robert Tisdale wrote:
What did I do wrong?
Hi,
it seems to be very old bug - look at
http://gcc.gnu.org/ml/gcc-prs/2000-q3/msg00288.html
To workaround it maybe try to use extra parameter: X<T>(X<S>, int).
The following code compiles well with gcc-3.4.
Yevgen
/////////////////////////////////////////////////
// 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, int i = 0);
friend
std::ostream& operator<<(std::ostream& os, const X<T>& x) {
return os << x.data();
}
};
#endif//GUARD_X_H 1
///////////////////////////////////////////
// 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, int i): D(x.data())
{
std::cerr << "conversion constructor" << std::endl;
}
template X<float>::X(const X<int>& x, int);
template X<float>::X(const X<float>& x);
void f()
{
X<float> a(X<float>(1.0));
X<float> b(X<int>(1));
}