Nie wiem co tu jest źle:
#include <iostream>
#include <math.h>
using namespace std;
class Punkt
{
float x,y;
string nazwa;
public:
void wyswietl()
{
cout<<nazwa<<"("<<x<<","<<y<<")"<<endl;
}
Punkt(string n = "P", float a = 0,float b = 0)
{
nazwa = n;
x = a;
y = b;
}
};
class Kolo :public Punkt //klasa kolo dziedziczy publicznie z klasy Punkt
{
string nazwa;
protected:
float r;
public:
void wyswietl()
{
cout<<"Kolo o nazwie: "<<nazwa<<endl;
cout<<"Srodek kola: ";
Punkt::wyswietl();
cout<<"Promien: "<<r<<endl;
cout<<"Pole kola: "<<M_PI*r*r<<endl;
}
Kolo(string nk = "kolko", string np = "S", float a = 0, float b = 0, float pr = 1)
:Punkt(np, a, b)
{
nazwa = nk;
r = pr;
}
};
class Kula :public Kolo //klasa Kula dziedziczy publicznie z klasy Kolo
{
string nazwa;
public:
void wyswietl()
{
cout<<"Kula o nazwie: "<<nazwa<<endl;
cout<<"Srodek kuli: ";
Punkt::wyswietl();
cout<<"Promien: "<<r<<endl;
cout<<"Obientosc kuli: "<<(M_PI*r*r*r)/(4/3)<<endl;
}
Kula(string nk = "kulka", string np = "K", float a = 0, float b = 0, float pr = 10)
:Punkt(np, a, b)
{
nazwa = nk;
r = pr;
}
};
int main()
{
Punkt p1;
p1.wyswietl();
cout<<endl<<endl;
Kolo k1;
k1.wyswietl();
cout<<endl<<endl;
Kula ku1;
ku1.wyswietl();
return 0;
}
Błędy, które wyrzuca kompilator:
||=== Build: Debug in dziedziczenie (compiler: GNU GCC Compiler) ===|
D:\Users\WGodlewski\Desktop\projekty\cpp\opp\dziedziczenie\main.cpp||In constructor 'Kula::Kula(std::string, std::string, float, float, float)':|
D:\Users\WGodlewski\Desktop\projekty\cpp\opp\dziedziczenie\main.cpp|66|error: type 'Punkt' is not a direct base of 'Kula'|
D:\Users\WGodlewski\Desktop\projekty\cpp\opp\dziedziczenie\main.cpp|68|error: 'nku' was not declared in this scope|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Jako że jestem początkujący to prosze o wyjaśnienie jak dla 6-ścio latka. Dziękuje.