#include %26lt;iostream%26gt;
using namespace std;
class SimpleCat
{public:
SimpleCat(int age, int weight);
SimpleCat(SimpleCat %26amp;);
~SimpleCat();
int getAge()const {return itsAge;}
void setAge(int ager) {itsAge = ager;}
void setWeight(int weighter) {itsAge = weighter;}
private:
int itsAge;
int itsWeight;};
SimpleCat::SimpleCat(int age, int weight)
{itsAge = age;
itsWeight = weight;}
SimpleCat::SimpleCat(SimpleCat %26amp;)
{cout %26lt;%26lt; "SimpleCat Copy Constructor\n";}
SimpleCat %26amp; FunctionOne(SimpleCat%26amp; theCat);
int main(){cout %26lt;%26lt; "Making a Cat\n";
SimpleCat Frisky(5,10);
cout %26lt;%26lt; "Inside Main.Frisky is " %26lt;%26lt; Frisky.getAge() %26lt;%26lt; " years old.\n"%26lt;%26lt; "Passing Frisky into FunctionOne\n";
FunctionOne(Frisky);
cout %26lt;%26lt; "Inside Main.Frisky is " %26lt;%26lt; Frisky.getAge() %26lt;%26lt; " years old.\n" %26lt;%26lt; "Passing Frisky into FunctionOne\n";
system("PAUSE");}
SimpleCat %26amp; FunctionOne(SimpleCat %26amp; theCat){
cout %26lt;%26lt; "Inside Function One\n" %26lt;%26lt; "Setting Frisky Age=10 %26amp; Weight=60\n";
theCat.setAge(10);
return(theCat);}
C++ help ?
I don't see "new" in your code, but the new operator provides dynamic storage/memory allocation.
I'm curious, what did you change to get it to compile? Thanx...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment