简体   繁体   English

双重自动转换功能定义,gcc错误:错误:预期的类型说明符

[英]Double Automatic Conversion Function definition, gcc error: error: expected type-specifier

I have a class with a conversion function in it. 我有一个带有转换功能的类。

class A {
  public:
    operator double() const;
};

Now I am defining it outside of the class defintion: 现在,我在类定义之外定义它:

operator A::double() const { return 32.5; }

I am using MinGW with GCC4.7 on it and I am getting a error: 我正在将MinGW与GCC4.7一起使用,但出现错误:

error: expected type-specifier

Anyone know what I am doing wrong? 有人知道我在做什么错吗?

You need a different order: 您需要不同的顺序:

A::operator double() const {return 32.5;}
    ^The function name is "operator double"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM