// Kol_popr_2013.cpp : Defines the entry point for the console application.
//
//Poprawic program tak, zeby fragment kodu, umieszczony w funkcji main,
//dzialal poprawnie.
#include "stdafx.h"
#include <iostream>
using namespace std;
class B1
{
protected:
double *ptr;
public:
B1(int dim);
B1() : ptr(0) {}
~B1() { if(ptr) delete [] ptr; }
void show();
};
B1::B1(int dim)
{
try
{
ptr = new double [dim];
}
catch(bad_alloc)
{
}
}
void B1::show()
{
if(ptr)
{
size_t no_it = _msize(ptr)/sizeof(ptr[0]);
for(size_t it = 0; it<no_it; ++it)
{
cout << it << " " << ptr[it] << endl;
}
}
}
class B2
{
protected:
char str[512];
public:
B2(char *sstr);
B2() { memset(str, 0, sizeof(str));}
void show() { cout << str << endl; }
};
B2::B2(char *sstr)
{
strcpy_s(str, sizeof(str), sstr);
}
class D : public B1, public B2
{
public:
//Stworzyc konstruktor sparametryzowany, przekazujacy
//rozmiar tablicy oraz wiersz tekstowy dla skladowych klas B1, B2
D(){}
void show(char *sstr) { cout << sstr << endl; B1::show(); B2::show(); }
};
int _tmain(int argc, _TCHAR* argv[])
{
D ob(10, "abcd");
for(size_t i=0; i<10; ++i)
ob[i] = i*i;
ob.show("ob");
D ob1 = ob;
ob1.show("ob1");
D ob2, ob3;
ob2 = ob1;
ob2.show("ob2");
ob = ob3;
ob3.show("ob");
system("pause");
return 0;
}