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

Tre*_*ors 1 c++ procedural struct typedef class

我必须构建一个具有两种数据类型的程序(Procedural C++).一个叫Elem,它是矢量元素(单维数组).一个名为Vector的包含一个unsigned int,用于表示数组的大小,也包含Elem本身的数组.我似乎无法弄清楚构造这些的正确方法,以便它们可以工作,因为我以前从未使用过程c ++做过任何事情.

这就是我所拥有的

typedef Elem {
    float Element;
}

typedef Vector {
    unsigned int size = 0;
    Elem* Array = new array[];
}
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误

C++ requires a type specifier for all declarations
typedef Elem {
~~~~~~~ ^
Run Code Online (Sandbox Code Playgroud)

并且

error: expected ';' after top level declarator
typedef Elem {
            ^
Run Code Online (Sandbox Code Playgroud)

我在这里不知所措,任何帮助将不胜感激!

Ola*_*che 5

你不说

typdef Elem {
...
};
Run Code Online (Sandbox Code Playgroud)

正确的方法是

struct Elem {
...
};
Run Code Online (Sandbox Code Playgroud)

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

有关一些小例子,另请参见类声明.