// 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;
#define MAX_SIZE 10
class B1
{
protected:
double aa[MAX_SIZE];
public:
B1(){ memset(aa, 0, sizeof(aa));}
void show();
};
void B1::show()
{
for(size_t it = 0; it<MAX_SIZE; ++it)
{
cout << it << " " << aa[it] << endl;
}
}
class B2
{
protected:
char *str;
public:
B2(char *sstr);
B2() : str(0) {}
~B2() {if(str) delete [] str; }
void show() { if(str) cout << str << endl; }
};
B2::B2(char *sstr)
{
try
{
size_t no_it = strlen(sstr)+1;
str = new char [no_it];
strcpy_s(str, no_it*sizeof(char), sstr);
}
catch(bad_alloc)
{
}
}
class D : public B1, public B2
{
public:
//Stworzyc konstruktor sparametryzowany, przekazujacy
//dane dla skladowych klas bazowych
D(char *sstr) : B2(sstr) {}
D(){}
void show(char *sstr) { cout << sstr << endl; B1::show(); B2::show(); }
};
int _tmain(int argc, _TCHAR* argv[])
{
D ob("abcd");
for(size_t i=0; i<MAX_SIZE; ++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;
}