Created
March 2, 2010 12:26
-
-
Save iwadon/319472 to your computer and use it in GitHub Desktop.
参照の型を途中で変更するとエラーになる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| int &foo() | |
| { | |
| static int foo_ = 0; | |
| return foo_; | |
| } | |
| int &bar() | |
| { | |
| return foo(); | |
| } | |
| unsigned int &baz() | |
| { | |
| return foo(); | |
| } | |
| int main() | |
| { | |
| foo() = 10; | |
| bar() = 20; | |
| baz() = 30; | |
| return 0; | |
| } | |
| // a.cpp: In function `unsigned int& baz()': | |
| // a.cpp:16: error: invalid initialization of reference of type 'unsigned int&' from expression of type 'int' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment