#include<iostream>
using namespace std;
class A {
public:
A(int ii = 0) : i(ii) {}
void show() { cout << "i = " << i << endl;}
private:
int i;
};
class B {
public:
B(int xx) : x(xx) {}
operator A() const { return A(x); }
private:
int x;
};
void g(A a)
{ a.show(); }
int main() {
B b(10);
g(b);
g(20);
getchar();
return 0;
}
一些語法在上面的代碼中任何人都可以解釋什麼是行麻煩的C++
A(int ii = 0) : i(ii) {}
意思,如何在程序的輸出
i = 10
i = 20
假設它是冒號部分你感到困惑,http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor – chris 2014-09-13 18:19:40
...和如果它是'int ii = 0':http://en.wikipedia.org/wiki/Default_argument – Drop 2014-09-13 18:22:27
C++教程/書的時間[[建議鏈接](http://www.cplusplus.com/doc/tutorial/) )] – 101010 2014-09-13 18:22:39