c++ - typedef 如何代替 Procedural c++ 的 struct/class?

标签 c++ class struct typedef procedural

我必须构建一个具有两种数据类型的程序(过程 C++)。一个叫做 Elem,它是 vector (一维数组)的一个元素。一个叫做 Vector,它包含一个 unsigned int 来表示数组的大小以及 Elem 本身的数组。我似乎无法找出正确的方法来构造这些,以便它们工作,因为我以前从未对过程 C++ 做过任何事情。

这是我的

typedef Elem {
    float Element;
}

typedef Vector {
    unsigned int size = 0;
    Elem* Array = new array[];
}

但是我收到了这个错误

C++ requires a type specifier for all declarations
typedef Elem {
~~~~~~~ ^

还有

error: expected ';' after top level declarator
typedef Elem {
            ^

我在这里不知所措,我们将不胜感激!

最佳答案

你不说

typdef Elem {
...
};

正确的做法是

struct Elem {
...
};

另请注意声明末尾的分号 ;

另见 Class declaration对于一些小例子。

关于c++ - typedef 如何代替 Procedural c++ 的 struct/class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40323933/

相关文章:

c++ - 更改 RGB 值

c++ - 数组索引中的感叹号有什么作用?

c++ - 如何在不使用 ide 的情况下为 MinGW 安装 allegro 5?

被跳过的 C++ 函数

objective-c - Xcode中类之间的简单变量传递

C# 编码(marshal)处理 C DLL struct bool

c++ - 如何将代码直接运行到带有文件系统的处理器中?

java - 注册对象字段值 Java

c++ - 在继承场景中使用基本结构作为函数参数

json - 如何在swift中处理不同的JSON HTTP响应