public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem with implicit conversion (GCC 3.4.1)
@ 2004-08-26 14:16 Boris von Loesch
  0 siblings, 0 replies; 4+ messages in thread
From: Boris von Loesch @ 2004-08-26 14:16 UTC (permalink / raw)
  To: gcc-help

Hello,

I have written a program that compiles just fine with GCC 3.3. With
GCC 3.4.1 it results in this error:

g++ -O0 -g3 -Wall -c -oTestp.o ../Testp.c
../Testp.c: In function `int main()':
../Testp.c:26: error: no match for 'operator<=' in 't <= 2.0e+0'

Please help me, I have no idea where the problem is.

Here is the code:

template <class T> class BasisF;
	
template <class T> inline bool operator<=(const BasisF<T> &a, const
BasisF<T> &b){return a.x <= b.x;}

template<class T> class BasisF{

public:
	T x;
	BasisF(const T &_x = T()): x(_x){}
	BasisF(const BasisF &_b): x(_b.x){}
	~BasisF(){}
	BasisF& operator= (const T &_x){
		 x(_x);
		 return *this;
	}
	friend bool operator<=<>(const BasisF &a, const BasisF &b);
	};

#define min(a,b) ((a) <= (b) ? (a) : (b))

int main(){
	BasisF<double> t(1);
	if (min(t,2.0)<=0) return 1;
	return 0;
}

Regards,
Boris

^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: Problem with implicit conversion (GCC 3.4.1)
@ 2004-08-26 17:46 lrtaylor
  0 siblings, 0 replies; 4+ messages in thread
From: lrtaylor @ 2004-08-26 17:46 UTC (permalink / raw)
  To: vonloesch, gcc-help

Well, you've declared a <= operator that can compare to BasisF objects,
but you're trying to compare a BasisF object with a double, which you
haven't created an operator for:

min(t,2.0)  -> ((t) <= (2.0) ? (t) > (2.0))

So, in your min macro, you are trying to compare the object t with the
double 2.0.  You don't have an operator for that.

Thanks,
Lyle

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Boris von Loesch
Sent: Thursday, August 26, 2004 3:55 AM
To: gcc-help@gcc.gnu.org
Subject: Problem with implicit conversion (GCC 3.4.1)

Hello,

I have written a program that compiles just fine with GCC 3.3. With
GCC 3.4.1 it results in this error:

g++ -O0 -g3 -Wall -c -oTestp.o ../Testp.c
../Testp.c: In function `int main()':
../Testp.c:26: error: no match for 'operator<=' in 't <= 2.0e+0'

Please help me, I have no idea where the problem is.

Here is the code:

template <class T> class BasisF;
	
template <class T> inline bool operator<=(const BasisF<T> &a, const
BasisF<T> &b){return a.x <= b.x;}

template<class T> class BasisF{

public:
	T x;
	BasisF(const T &_x = T()): x(_x){}
	BasisF(const BasisF &_b): x(_b.x){}
	~BasisF(){}
	BasisF& operator= (const T &_x){
		 x(_x);
		 return *this;
	}
	friend bool operator<=<>(const BasisF &a, const BasisF &b);
	};

#define min(a,b) ((a) <= (b) ? (a) : (b))

int main(){
	BasisF<double> t(1);
	if (min(t,2.0)<=0) return 1;
	return 0;
}

Regards,
Boris

^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: Problem with implicit conversion (GCC 3.4.1)
@ 2004-08-26 19:54 Suresh Lakshmanan
  2004-08-26 22:17 ` Boris von Loesch
  0 siblings, 1 reply; 4+ messages in thread
From: Suresh Lakshmanan @ 2004-08-26 19:54 UTC (permalink / raw)
  To: gcc-help; +Cc: vonloesch

Try the code below. You could use std::min template in STL, so that you can 
force conversion
to the template parameter.

template<class T> class BasisF {
	T x;
public:

	BasisF(const T &_x = T()): x(_x) {}
	BasisF(const BasisF &_b): x(_b.x) {}
	~BasisF() {}

	BasisF& operator= (const T &_x){
		 x(_x);
		 return *this;
	}

	friend bool operator<=(const BasisF &a, const BasisF &b) {
		return a.x <= b.x;
	}
};

#define min(a,b) ((a) <= (b) ? (a) : (b))

int main(){
	BasisF<double> t(1);
	if (min(t, 2.0)<= 0) {
		return 1;
	}

	return 0;
}

Thanks,
L.Suresh.

_________________________________________________________________
Sell what you donÂ’t Need.We help you Ship it out. 
http://go.msnserver.com/IN/54179.asp Click Here!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-08-26 19:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-26 14:16 Problem with implicit conversion (GCC 3.4.1) Boris von Loesch
2004-08-26 17:46 lrtaylor
2004-08-26 19:54 Suresh Lakshmanan
2004-08-26 22:17 ` Boris von Loesch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).