I have a problem with redefinition I tried #pragma once and #ifndf statements but none of these worked for me. My main.cpp
#include <iostream>
#include "kolo.h"
#include "prostokat.h"
#include "trojkat.h"
using namespace std;
//overloading
void zmienno(float x)
{
cout<<x;
}
void zmienno(int x)
{
cout<<x;
}
int main()
{
//tworzenie obiektu zmienna lokalna
Kolo kolo(5);
Trojkat trojkat(1,2,3);
Prostokat prostokat(1,2);
//wskaznik
Kolo * wskkolo = new Kolo(5);
Trojkat * wsktrojkat = new Trojkat(1,2,3);
Prostokat * wskprostokat = new Prostokat(1,2);
//konstruktory zaprezentowane wyżej, metody np:
double pole = kolo.Pole(); //pole kola
double obwod = wsktrojkat->Obwod(); //obwod trojkata
kolo.SetR(3);
pole = kolo.Pole(); // inne pole po zmiane R
FiguraPlaska *wsk[3];
wsk[0]=wskkolo;
wsk[1]=wskprostokat;
wsk[2]=wsktrojkat;
for(int i=0;i<3;i++)
{
cout<<wsk[i]->Pole()<<endl;//metody wirtualne
}
wskprostokat->~Prostokat();
wskkolo->~Kolo();
wsktrojkat->~Trojkat();
// overriding -> polimorfizm metody pole, obwod
// overloading: funkcje w linii nr8
zmienno(2);
//ta sama nazwa funkcji, rozszerzona o inne typy argumentow
delete[]wsk;
delete wskkolo,wskprostokat,wsktrojkat;
return 0;
}
and one of my header files as the structure in every file is the same, including figuraplaska.h
#pragma once
#include "figuraplaska.h"
class Prostokat : public FiguraPlaska {
private:
double a,b;
protected:
void Wypisz(std::ostream& out) const override;
public:
Prostokat(double a, double b);
double GetA() const;
void SetA(double a);
double GetB() const;
void SetB(double b);
double Obwod() override;
double Pole() override;
~Prostokat() override;
};
and figuraplaska.h
#include <iostream>
using namespace std;
class FiguraPlaska {
protected:
virtual void Wypisz(std::ostream& out) const = 0;
friend std::ostream& operator<<(std::ostream& os, const FiguraPlaska& figura);
public:
virtual double Pole() = 0;
virtual double Obwod() = 0;
virtual ~FiguraPlaska();
};
Errors are
[Running] cd "/home/bj/Pulpit/PO1/" && g++ main.cpp -o main && "/home/bj/Pulpit/PO1/"main
In file included from prostokat.h:2:0,
from main.cpp:3:
figuraplaska.h:5:7: error: redefinition of ‘class FiguraPlaska’
class FiguraPlaska {
^~~~~~~~~~~~
In file included from kolo.h:2:0,
from main.cpp:2:
figuraplaska.h:5:7: note: previous definition of ‘class FiguraPlaska’
class FiguraPlaska {
^~~~~~~~~~~~
In file included from trojkat.h:2:0,
from main.cpp:4:
figuraplaska.h:5:7: error: redefinition of ‘class FiguraPlaska’
class FiguraPlaska {
^~~~~~~~~~~~
In file included from kolo.h:2:0,
from main.cpp:2:
figuraplaska.h:5:7: note: previous definition of ‘class FiguraPlaska’
class FiguraPlaska {
^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:45:13: warning: deleting array ‘wsk’
delete[]wsk;
^~~
[Done] exited with code=1 in 2.043 seconds
I have no clue how can I repair it, any suggestions? None of help in the internet worked for me :/