jeudi 20 mai 2021

How to define protected constructor? in c++ [closed]

C++ Code:

class Tocka {
protected:

float x,y;
Tocka(float x, float y) : x(x) , y(y) {}
friend float udaljenost(Tocka &T1, Tocka &T2);

How can i declare x,y in main?

i get an error Tocka::Tocka(float,float) is protected

I must let protected because the professor said.


this is the full code that we need to supplement:

    class Tocka {
protected:
float x,y;
Tocka(x,y);
friend float udaljenost(Tocka &T1, Tocka &T2);
};
class Cetverokut {
protected:
Tocka T1,T2,T3,T4;
Cetverokut(Tocka &T1,Tocka &T2,Tocka &T3, Tocka& T4);
float opseg();
float povrsina();
float ispis();
};
class Paralelogram : public Cetverokut {
public:
Paralelogram(Tocka &T1,Tocka &T2,Tocka &T3, Tocka& T4);
float opseg();
float povrsina();
};
class Trapez : public Cetverokut {
public:
Trapez(Tocka &T1,Tocka &T2,Tocka &T3, Tocka& T4);
float opseg();
float povrsina(); }; 

Aucun commentaire:

Enregistrer un commentaire