このコードのコンパイル方法がわかりません。誰かがそこで何が起こっているのか説明してもらえますか.
#include <iostream>
using namespace std;
class B
{
public:
B(const char* str = "\0") //default constructor
{
cout << "Constructor called" << endl;
}
B(const B &b) //copy constructor
{
cout << "Copy constructor called" << endl;
}
};
int main()
{
B ob = "copy me"; //why no compilation error.
return 0;
}
optput は次のとおりです。呼び出されるコンストラクター
PS: これ以上にふさわしいタイトルが思い浮かびませんでした。より良いタイトルを考えられる方は、修正してください。