help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it valid to call 'operator T()' directly in an template function?


From: fik
Subject: Re: Is it valid to call 'operator T()' directly in an template function?
Date: Thu, 18 Nov 2004 10:54:29 +1100

Compiles fine under VC7.1


"Feng Ye" <fengye@hotpop.com> wrote in message 
news:mailman.3236.1100678397.8225.help-gplusplus@gnu.org...
> Hi,
>   I got this error when compiling the following code by g++ 3.4.3.
>
>   error: 'const class Field' has no member named 'operator T'
>
>   The comeau online c++ reports no error. Is it a bug of g++?
>
> Regards,
> Feng Ye
>
> =====================8<===========================
> class Field
> {
> public:
>     operator int() const { return *(int*)value; }
>     operator char*() const { return (char*)value; }
>
> private:
>     void* value;
> };
>
> template<class T>
> class Test
> {
> public:
>     void setValue(int){}
>     void setValue(char*){}
>
>     void fromField(const Field& f);
> };
>
> template<class T>
> void Test<T>::fromField(const Field& f)
> {
>     setValue( f.operator T() );
> }
>
> int main()
> {
>     Field f;
>     Test<int> t;
>
>     t.fromField(f);
> }
>
>
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]