三个类相互链接
Three classes linked to each other
Kelvin.h
class CelciusDeg;
class FarenheitDeg;
class Kelvin
{
double val;
public:
friend void show(const Kelvin&);
friend void CelciusDeg::count(const Kelvin&);
friend void FarenheitDeg::count(const Kelvin&);
void count(const CelciusDeg&);
void count(const FarenheitDeg&);
Kelvin();
Kelvin(double);
~Kelvin();
};
摄氏
度class Kelvin;
class FarenheitDeg;
class CelciusDeg
{
double val;
public:
friend void show(const CelciusDeg&);
friend void Kelvin::count(const CelciusDeg&);
friend void FarenheitDeg::count(const CelciusDeg&);
void count(const Kelvin&);
void count(const FarenheitDeg&);
CelciusDeg();
CelciusDeg(double);
~CelciusDeg();
};
华氏度
class CelciusDeg;
class Kelvin;
class FarenheitDeg
{
double val;
public:
friend void show(const FarenheitDeg&);
friend void Kelvin::count(const FarenheitDeg&);
friend void CelciusDeg::count(const FarenheitDeg&);
void count(const CelciusDeg&);
void count(const Kelvin&);
FarenheitDeg();
FarenheitDeg(double);
~FarenheitDeg();
};
我正在尝试制作一个程序,该程序可以将温度值存储在 3 种不同类型的温度对象中并将它们相互计数。如何使用前向声明使计数方法工作?
我想你可以调用非默认构造函数并将其插入到两个朋友的函数中
你好,我会做一个不同的设计:
class Kelvin
{
double val;
public :
explicit Kelvin(double val);
double getVal() const;
};
class Farenheit
{
double val;
public :
explicit Farenheit(double val);
double getVal() const;
};
class Celcius
{
double val;
public :
explicit Celcius(double val);
double getVal() const;
};
Kelvin toKelvin(Farenheit & o);
Kelvin toKelvin(Celcius & o);
Celcius toCelcius(Farenheit & o);
Celcius toCelcius(Kelvin & o);
Farenheit toFarenheit(Kelvin & o);
Farenheit toFarenheit(Celcius & o);
相关文章:
- 在使用 gSoap 链接多个 SOAP 服务时启用保持活动状态
- 如何使用模板元编程在自由函数C++链接两个不相关的类
- 链接两个使用 c++ 构建的库_static
- 当我链接两个静态C++库时,我可以在两个主函数库中有两个主要功能吗?
- 如何链接两个LLVM位码模块?
- gcc (g++) 如何链接多个库?
- 如何将 Pybind11 与 CMAKE 一起使用以链接 2 个模块
- 在 Linux 中编译/链接多个 C++ 库
- CMake 链接 2 个具有相对路径的库
- 在没有额外代码的情况下链接两个独立类的最通用方法是什么?
- 在 Linux 上的 Visual Studio 中链接两个项目
- 在同一C++项目中链接两个不同版本的 protobuf 库
- 我如何使用上一个块的哈希链接2个块
- 如何链接两个ArUco标记的姿势
- 链接2个CPP文件
- 如何在c makefile中链接多个.so文件
- CMakeLists配置以链接两个C++项目
- 如何从命令行编译和链接多个文件
- 在 c++ 中链接多个对象文件,但没有输出
- Xcode 不链接两个结构