pippo
2007-01-17, 13:20:28
#include <iostream>
using namespace std;
class SimpleCat {
public:
SimpleCat();
SimpleCat(SimpleCat&);
~SimpleCat();
int GetAge() const { return itsAge; }
void SetAge(int age) { itsAge = age; }
private:
int itsAge;
};
SimpleCat::SimpleCat()
{
cout << "SimpleCat Konstruktor...\n";
itsAge = 1;
}
SimpleCat::SimpleCat(SimpleCat&)
{
cout << "SimpleCat Kopierkonstruktor...\n";
}
SimpleCat::~SimpleCat()
{
cout << "SimpleCat Destruktor...\n";
}
const SimpleCat * const FunctionTwo (const SimpleCat * const theCat);
int main()
{
cout << "Eine Katze erzeugen...\n";
SimpleCat Frisky;
cout << "Frisky ist " ;
cout << Frisky.GetAge();
cout << " Jahre alt\n";
int age = 5;
Frisky.SetAge(age);
cout << "Frisky ist " ;
cout << Frisky.GetAge();
cout << " Jahre alt\n";
cout << "FunctionTwo aufrufen...\n";
FunctionTwo(&Frisky);
cout << "Frisky ist " ;
cout << Frisky.GetAge();
cout << " Jahre _alt\n";
}
cout << a << endl << b;
return 0;
}
// FunctionTwo uebernimmt einen konstanten Zeiger
const SimpleCat * const FunctionTwo (const SimpleCat * const theCat)
{
cout << "FunctionTwo. Rueckkehr...\n";
cout << "Frisky ist jetzt " << theCat->GetAge();
cout << " Jahre alt \n";
// theCat->SetAge(8); const!
return theCat;
}
Was ich nicht ganz verstehe ist, warum FunctionTwo einen Rückgabewert besitzt, bzw. warum der Typ nicht void ist. In der "main" wird ja sogesehen kein Rückgabewert entgegen genommen.
using namespace std;
class SimpleCat {
public:
SimpleCat();
SimpleCat(SimpleCat&);
~SimpleCat();
int GetAge() const { return itsAge; }
void SetAge(int age) { itsAge = age; }
private:
int itsAge;
};
SimpleCat::SimpleCat()
{
cout << "SimpleCat Konstruktor...\n";
itsAge = 1;
}
SimpleCat::SimpleCat(SimpleCat&)
{
cout << "SimpleCat Kopierkonstruktor...\n";
}
SimpleCat::~SimpleCat()
{
cout << "SimpleCat Destruktor...\n";
}
const SimpleCat * const FunctionTwo (const SimpleCat * const theCat);
int main()
{
cout << "Eine Katze erzeugen...\n";
SimpleCat Frisky;
cout << "Frisky ist " ;
cout << Frisky.GetAge();
cout << " Jahre alt\n";
int age = 5;
Frisky.SetAge(age);
cout << "Frisky ist " ;
cout << Frisky.GetAge();
cout << " Jahre alt\n";
cout << "FunctionTwo aufrufen...\n";
FunctionTwo(&Frisky);
cout << "Frisky ist " ;
cout << Frisky.GetAge();
cout << " Jahre _alt\n";
}
cout << a << endl << b;
return 0;
}
// FunctionTwo uebernimmt einen konstanten Zeiger
const SimpleCat * const FunctionTwo (const SimpleCat * const theCat)
{
cout << "FunctionTwo. Rueckkehr...\n";
cout << "Frisky ist jetzt " << theCat->GetAge();
cout << " Jahre alt \n";
// theCat->SetAge(8); const!
return theCat;
}
Was ich nicht ganz verstehe ist, warum FunctionTwo einen Rückgabewert besitzt, bzw. warum der Typ nicht void ist. In der "main" wird ja sogesehen kein Rückgabewert entgegen genommen.