Any comments: mail me
#include <iostream>
#include <string>
class Klasse {
public:
Klasse(const Klasse & copy)
{
std::cout << "copy constructor" << std::endl;
str = copy.str;
};
Klasse()
{std::cout << "default constructor" << std::endl; };
~Klasse()
{ std::cout << "destructor" << std::endl; };
void operator=(const Klasse & copy)
{
std::cout << "copy operator" << std::endl;
str = copy.str;
};
std::string str;
};
Klasse dressmeup()
{
std::cout << "in dressmeup()" << std::endl;
Klasse maklasse;
maklasse.str = "42";
std::cout << "out dressmeup()" << std::endl;
return maklasse;
}
int main()
{
std::cout << "dressmeup call()\n";
Klasse laklasse = dressmeup();
std::cout << "str=" << laklasse.str << std::endl;
std::cout << "leaving" << std::endl;
} thomas@athlon:~$ g++ --version 2.95.4 thomas@athlon:~$ g++ test.cpp -o testcpp thomas@athlon:~$ ./testcpp dressmeup call() in dressmeup() default constructor out dressmeup() copy constructor destructor str=42 leaving destructor thomas@athlon:~$
thomas@athlon:~$ g++-3.1 --version g++-3.1 (GCC) 3.1.1 20020606 (Debian prerelease) Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. thomas@athlon:~$ g++-3.1 test.cpp -o testcpp thomas@athlon:~$ ./testcpp dressmeup call() in dressmeup() default constructor out dressmeup() str=42 leaving destructor thomas@athlon:~$