C++ C++;:重新定义';类图APLASKA';
我的运动有问题。如果我加上Trojkat.h,它就不起作用了。如果我对它进行评论,那么它是有效的。 我不知道为什么它不起作用。我80%确信一切都很好,有些东西有问题。。。无论如何,希望有人能帮助我 图A.hC++ C++;:重新定义';类图APLASKA';,c++,C++,我的运动有问题。如果我加上Trojkat.h,它就不起作用了。如果我对它进行评论,那么它是有效的。 我不知道为什么它不起作用。我80%确信一切都很好,有些东西有问题。。。无论如何,希望有人能帮助我 图A.h #include <iostream> class FiguraPlaska { protected: virtual void Wypisz(std::ostream& out) const = 0; friend std::ostream& ope
#include <iostream>
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(); //DESTRUKTOR
};
Prostokat.h
#ifndef PROSTOKAT_H
#define PROSTOKAT_H
#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;
};
#endif
您也应该在
FiguraPlaska.h
中放置类似的include块
#ifndef FIGURA_H
#define FIGURA_H
class FiguraPlaska ....
#endif
为什么??因为当您实际使用当前代码编译时,您会两次包含同一个类
e、 g.获取一个
#include "prostokat.h"
#include "trojkat.h"
然后,在代码中展开include后,看起来如下所示:
class FiguraPlaska // because of include from prostokat
class Prostokat // because prostokat.h
class FiguraPlaska // because of include from trojkat <- BOOM
class Trojkat // because trojkat.h
class FiguraPlaska//因为prostokat的包含
类Prostokat//因为Prostokat.h
类FiguraPlaska//因为trojkat的包含,“相似”是什么意思?它和Prostokat.h不一样吗?或者与其他类似?@Kawson在Trojkat.h
和Prostokat.h
中添加了一个头球后卫。您需要在所有头文件中添加类似的保护FiguraPlaska.h
缺少它。谢谢你,伙计,现在我得到了它(我两次了解了关于包含同一类的内容,但不知道我也必须把它放在基类中)。谢谢@Kawson您可能想看一看#pragma once
-,因为它可以很好地替代像Yoursounds这样的案例,就像典型的Polipuda练习:>
class FiguraPlaska // because of include from prostokat
class Prostokat // because prostokat.h
class FiguraPlaska // because of include from trojkat <- BOOM
class Trojkat // because trojkat.h