gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:40:23 24 4
gpt4 key购买 nike

我必须构建一个具有两种数据类型的程序(过程 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com