Witam mam problem jak w temacie. Polega on na tym że za każdym razem inicjowany jest konstruktor w klasie Colors to wywoływany jest za każdym razem konstruktor domyślny. Tak więc zamiast oczekiwanego przeze mnie wyniku, czyli przekazania z klasy Colors do klasy Rysunek zmiennych o wartościach a=205,a=1 i c=1 i wypisania ich na ekran, to program przekazuje te zmienne do klasy Rysunek ale ich wartości są takie jak konstruktorze domyślnym a=204, b=0, c=0. Teraz mam pytanie jak naprawić ten problem żeby przekazywane zmienne do klasy Rysunek miały wartości z funkcji ,,Colors::Colors( int kolor)'' a nie z konstruktora domyślnego? :)
#include <string.h>
#include<iostream>
#include <sstream>
#include <sstream>
#include <sstream>
class Colors
{
public:
Colors( int kolor);
int a;
int b;
int c;
public:
Colors(int f, int g, int h)
{
this->a = f;
this->b = g;
this->c = h;
}
Colors() {
a=204;
b=0;
c=0;
}
~Colors(){};
};
Colors::Colors( int kolor)
{
switch(kolor )
{
case 1:
a=205;
b=1;
c=1;
std::cout << "kolor o zmiennej " <<a<<" "<<b<<" "<<c;
Colors( a, b, c);
break;
default:
std::cout << "nie rób nic" <<endl;
break;
}
}
class Rysunek : public Colors
{
void draw( void );
public:Rysunek(int a,int b,int c) : Colors(a,b,c) {}
};
void Rysunek::draw( void )
{
cout<<"zmienne:"<<a<<" ,"<<b<<" ,"<<c<<endl;
}
int main()
{
int kolor=1;
Colors jakis(kolor);
Rysunek draw(void);
return 0;
}