Tremors Tremors - 5 months ago 33
C++ Question

How does typedef work in place of struct/class for Procedural c++?

I have to build a program(Procedural C++) that has two data types. One called Elem that is an element of a vector(single dimensional array). and One called Vector that contains an unsigned int for the size of the array and also the array of Elem's itself. I can't seem to figure out the correct way to structure these so that they work as I have never done anything with procedural c++ before.

This is what I have

typedef Elem {
float Element;

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

but I'm getting this error

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

and also

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

I'm at a loss here, any help would be appreciated!


You don't say

typdef Elem {

The correct way is

struct Elem {

Note also the semicolon ; at the end of the declaration.

See also Class declaration for some small examples.