creating a struct

Mar 30, 2016 at 8:55pm
//CONSTRUCTOR
// pre: d is the character data being counted,
// c is the count.
// post: allocates memory for a new frequency record
// return: a reference to the new record

Frequency *createFrequency(char d, int c){
struct Frequency {
int c;
char d;
};
return createFrequency;
}

i beileve my problem lies in the return statement it says i need to return a refrence to my struct but im not entirely certain how to do that
Mar 30, 2016 at 10:06pm
Why are you defining the structure inside the function body? Don't do that - define the structure first and then the function later.

Also, your function is actually a static factory, not a constructor. Static factories have their uses but in this case I believe you should use an ordinary constructor instead.
Last edited on Mar 30, 2016 at 10:07pm
Topic archived. No new replies allowed.