[ create a new paste ] login | about

Link: http://codepad.org/SdAlwuoQ    [ raw code | output | fork | 2 comments ]

DigitalGhost - C++, pasted on Dec 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class foo {
  friend int lvalue_only(foo &);
  int f() const {
    return 1;
  }
};

int lvalue_only(foo & x) {
  return x.f();
}

int main() {
  foo x;
  lvalue_only(x);
  lvalue_only(static_cast<foo&>(foo()));
}


Output:
1
2
3
In function 'int main()':
Line 15: error: invalid static_cast from type 'foo' to type 'foo&'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments:
posted by DigitalGhost on Dec 29
rvalue からのメンバ関数の呼び出しをできなくする方法
reply
posted by DigitalGhost on Dec 29
これはstatic_cast関係なくて、本物はこっちです。 http://codepad.org/ASHNEv2O
reply