In this piece of code:
PointType * createPoint (int x, int y, int value) {
PointType * vertex = (PointType *) malloc (sizeof (PointType));
vertex - & gt; x = x;
vertex - & gt; y = y;
vertex - & gt; value = value;
return vertex;
}
An error occurs:
main.cpp: 29: 1: error: expected initializer before 'PointType'
PointType * createPoint (int x, int y, int value) {
^
The structure itself looks like this:
typedef struct Point PointType;
struct Point {
int x;
int y;
int value;
};
What could be the problem?
Answer 1, authority 100%
This error is usually caused by a missing semicolon.
Look at the piece of code just before the problem line. If it is preceded by #include
, look at the end of the header (#include
stupidly includes the header text at the point where it is mentioned).
This piece of code is a class or structure definition, do not forget that in C++ it must also end with a semicolon. The same goes for pre-declarations of functions and globals, but in such places, mistakes are usually less common.
Example:
(x.h)
# ifndef X_H
#define X_H
double variable // & lt; - missing semicolon here
#endif
(x.cpp)
# include "x.h"
PointType * createPoint (int x, int y, int value) {// & lt; - error will be reported here
// ...
Proof: http://ideone.com/KHT4pz