How to use a structure pointer through a structure public member definition

Why doesn't this compile?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
struct hi(){
 void other();
}histructure;

void hi::other(){
 std::cout << "Hi!" << std::endl;
}

struct hello() {
 void hellothere();
}hellostructure;

void hello::hellothere(){
 histructure *stuff;
 stuff.other();
};


int main(int argc, char *argv[])
{
 
  hellostructure.hellothere(); 
 
  return 0;
}



Makes no sense the structure is written before the structure member function is called so why is there compile errors ??...
Last edited on
struct hi(){ <-- take out the () next to struct names


histructure *stuff; <-- histructure isn't a type - I think you mean to say stuff is a pointer to a hi struct? Then stuff will point to the address of histructure?

and then stuff->other();
Last edited on
Thanks for those rather beneficial tips but ummm ...

That still doesn't solve the problem how to use a pointer towards structure through another structure public member function?

1
2
3
4
void hello::hellothere(){
 histructure *stuff;
 stuff.other();
};

^^ That won't compile. ^^
Last edited on
histructure *stuff; <-- histructure isn't a type - I think you mean to say stuff is a pointer to a hi struct? Then stuff will point to the address of histructure?

and then stuff->other();


1
2
3
4
5
void hello::hellothere(){
 hi *stuff;
 stuff = &histructure;
 stuff->other();
}
Topic archived. No new replies allowed.