Skip to content

Instantly share code, notes, and snippets.

@iwadon
Created March 2, 2010 12:26
Show Gist options
  • Select an option

  • Save iwadon/319472 to your computer and use it in GitHub Desktop.

Select an option

Save iwadon/319472 to your computer and use it in GitHub Desktop.
参照の型を途中で変更するとエラーになる。
#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