小编hur*_*tch的帖子

将具有条件的Ada记录转换为C++

我有一个任务,我需要将一些Ada代码转换为C++代码,使其尽可能与Ada代码相似.Ada代码如下

    type Shape is (Circle, Triangle, Rectangle);
    type Colors is (Red, Green, Blue);
    type Figure(Form: Shape := Circle) is
        record
            Filled: Boolean;
            Color: Colors;
            case Form is 
                when Circle =>
                    Diameter: Float;
                when Triangle =>
                    Left_Side: Integer;
                    Right_Side: Integer;
                    Angle: Float;
                when Rectangle =>
                    Side_1: Integer;
                    Side_2: Integer;
            end case;
        end record;
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用一个class但是根据问题的语言和老师的个性来判断我认为他正在寻找一个struct.我不清楚如何创建一个内部不同情况所需的逻辑struct.老师非常特别,所以我认为需要最小的内存占用.

我是CSc的学生,如果解决方案很简单,请原谅我.谢谢!

更新:所以最终答案比我想象的要简单.

enum Shape {Circle, Triangle, Rectangle};
enum Colors {Red, Green, Blue};
struct Figure {
  bool Filled;
  Colors Color;
  Shape Form; …
Run Code Online (Sandbox Code Playgroud)

c++ struct ada

3
推荐指数
1
解决办法
310
查看次数

标签 统计

ada ×1

c++ ×1

struct ×1