[ create a new paste ] login | about

Link: http://codepad.org/fJSS7dUv    [ raw code | output | fork ]

C++, pasted on Dec 19:
#include <iostream>
#include <cstring>

using namespace std;

class Base
{
public:
	Base()
	: value_(10)
	, hoge_(20)
	{
		cout << "Base::Base()" << endl;
	}
	virtual ~Base() {
		cout << "Base::~Base()" << endl;
	}
	void print() {
		cout << value_ << endl;
	}
private:
	int value_;
	int hoge_;
};

class Derivation : public Base
{
public:
	Derivation()
	: value_(100)
	, hoge_(10)
	{
		cout << "Derivation::Derivation()" << endl;
	}
	virtual ~Derivation() {
		cout << "Derivation::~Derivation()" << endl;
	}
	void print() {
		cout << value_ << endl;
	}
private:
	int value_;
	int hoge_;
};

int main()
{

	cout << "Base:" << sizeof(Base) << endl;
	cout << "Derivation:" << sizeof(Derivation) << endl;
	
	Base* d = new Derivation[10];
	for (int i = 0; i < 10; ++i) {
		d[i].print();
	}
	delete [] d;
	
	return 0;
}


Output:
Base:12
Derivation:20
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
Base::Base()
Derivation::Derivation()
10
10
20
134540080
100
10
10
20
134540080
100

Segmentation fault


Create a new paste based on this one


Comments: