#include "iostream"
using namespace std;
class counter
{
private:
int itsval;
public:
counter(){}
counter(int val){}
int getitsval()const {return itsval;}
};
void main()
{
int theint =5;
counter thectr=theint;
cout<<thectr.getitsval ()<<endl;
}
=========================================
#include "iostream"
using namespace std;
class counter
{
private:
int itsval;
public:
counter():itsval(0){}
counter(int val):itsval(val){}
~counter(){}
int getitsval()const {return itsval;}
};
void main()
{
int theint =5;
counter thectr=theint;
cout<<thectr.getitsval ()<<endl;
}
第一段代码结果不正确,第二段正确。为什么