Why this type having ERROR??

I want to define function in class Region but line 4 and 1 (in regio.cpp) doesn't mach what am I missing??
1
2
3
4
5
6
7
8
9
class Region {
public:
	Region();
	void htonHeader(struct , char ); //error in this line
	virtual ~Region();
private:
	typedef struct Header {
	    uint16_t f1;
	}h;

region.cpp:
1
2
3
4
5
6
void Region::htonHeader(struct  Header h, char buffer[8]) { //and this line
uint16_t u16;
uint32_t u32;
 u16 = htons(h.f1);
memcpy(buffer, &u16, 2);
}
Last edited on
When you declare the function you are not mentioning the complete type names.

struct is not a type. You need to mention the struct type name like you do when you define the function. You also need to define the Header struct before this point (not after). Not sure why you are using typedef when you are defining the struct. It's something you usually see in C but in C++ it's generally not needed.
1
2
3
typedef struct Header {
	uint16_t f1;
}h;


The second parameter is a pointer to a char so you have to state that by writing char*, char[], or char[8]. Note that the size 8 is ignored by the compiler so there isn't really much point writing it out.
Last edited on
closed account (48T7M4Gy)
4: void htonHeader(Header, char* ); //error in this line

1: void Region::htonHeader( Header h, char* buffer)
@kemort @peter thank you for your answer, I change my code but I have error yet!!
Last edited on
Please post the new code and errors.
@zhunge thank you my problem was solved......
Last edited on
Topic archived. No new replies allowed.