Zdravím, mám problémy s kopírovacím konstructorem, který se nevolá, když požiju kteroukoliv funkci v třídě. Mám přečtenou knihu Naučte se C++ za 21 dní (2007).Zde je příklad:
#include <iostream>
using namespace std;
class Division
{
public:
Division ();
Division (Division&);
~Division ();
float GetDownValue () const {return itsDownValue;}
float GetResultValue () const {return itsResultValue;}
float GetUpValue () const {return itsUpValue;}
void SetDownValue (float downValue) {itsDownValue = downValue;}
void SetUpValue (float upValue) {itsUpValue = upValue;}
class xNullDownValue {};
private:
float itsDownValue;
float itsResultValue;
float itsUpValue;
};
Division::Division ():
itsDownValue(1),
itsResultValue(0),
itsUpValue(0)
{
cout << "Constructor" << endl;
}
Division::Division (Division&)
{
cout << "copy Constructor" << endl;
if (itsDownValue == 0)
{
throw xNullDownValue();
}
itsResultValue = itsUpValue/itsDownValue;
}
Division::~Division ()
{
cout << "Destructor" << endl;
}
int main(int argc, char *argv[])
{
try
{
Division first;
cout << first.GetResultValue () << endl;
}
catch (Division::xNullDownValue)
{
cout << "Down value is Null!" << endl;
}
catch (...)
{
cout << "error!" << endl;
}
cout << "Press the enter key to continue ...";
cin.get();
return 0;
}