help-gplusplus
[Top][All Lists]
Advanced

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

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


From: Feng Ye
Subject: Is it valid to call 'operator T()' directly in an template function?
Date: Wed, 17 Nov 2004 15:32:24 +0800
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

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]