I know that we could use MIL to call a constructor in a constructor like the following code. But I would also like to ask whether there are any other methods to call the constructor in a constructor without using MIL? How could I change the following code to call a constructor in a constructor without MIL? Thanks a lot.
#include <iostream>
using namespacestd;
class Food{
private:
int a;
int b;
public:
Food(){cout << "default constructor" << endl};
Food(int x = 0, int y ) { a = x; b = y;};
Food(const Food& z) : Food(z.b){cout << "using mil" << endl; };
};
int main( ){
Food apple; // default constructor
Food orange = apple; //copy constructor
return 0;
}```
Aucun commentaire:
Enregistrer un commentaire