2012-03-09 20 views
1

次のクラスはcompileには思われるが、変換演算子が呼び出されることはありません:過負荷参照変換

class A 
{ 
public: 
    operator A() const { std::cout << "A() called" << std::endl; return *this; } 
    operator A&() { std::cout << "A&() called" << std::endl; return *this; } 
    operator const A&() const { std::cout << "const A&() called" << std::endl; return *this; } 
}; 

は単に無視自体への参照への変換を指定する機能ですか? warning: this statement has no effectを静的キャスト用:

+2

私は誰かが標準を引用すると確信していますが、その間に私は明らかにするでしょう:これはまったく意味がありません。 – David

答えて

1

は、ここで私を与えたgccの上-Wall -Wextra -pedantic -ansiを使用して、12.3.2

また

A conversion function is never used to convert a (possibly cv-qualified) object to the (possibly cv-qualified) same object type (or a reference to it)

からの引用です。 (また、clang onlineを試してみると、コンパイラのエラーメッセージが表示されます)。

関連する問題