Suppose we have 2 versions of the same class Simple:
1.
#include <iostream>
using namespace std;
class Simple
{
public:
Simple() { }
Simple(int c)
{
data = c;
cout << data << endl;
}
private:
int data;
};
int main()
{
Simple obj(3);
return 0;
}
2.
#include <iostream>
using namespace std;
class Simple
{
public:
Simple() { }
Simple(int c) : data(c) { cout << data << endl; }
private:
int data;
};
int main()
{
Simple obj(3);
return 0;
}
Both compile, run and give the same result. Which one should be used and is there any internal difference between them? Thanks.