Pointers Pointing to Pointers Pointing to Class Objects

As it turns out I need to point to a class variable from a certain function, but the only way this is possible is by pointing to a pointer in another function that points to a class in my main function. I know this may be a newbie question but how is this done, exactly? or is it even possible?
Post some code - let's see what you are up to (sounds a bit mmmmmm....)
Last edited on
my project is around 1000 lines so i will instead make up an example
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
26
27
28
29
#include <iostream>

class myclass
{
int myvar;
}

void firstfunc(myclass * myclass1);
void secondfunc(myclass ** myclass1);

int main()
{
myclass myclass1;
firstfunc(&myclass1);
return 0;
}

void firstfunc(myclass * myclass1)
{
secondfunc(&myclass1);
return;
}

void secondfunc(myclass ** myclass1);
{
std::cout << myclass1->myvar;
return;
}


this code would give me an error left of ->myvar must have struct
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
26
27
28
29
#include <iostream>

class myclass
{
     public:  //*** I know you meant this to be public
int myvar;
}

void firstfunc(myclass * myclass1);
void secondfunc(myclass * myclass1); //just a pointer not a pointer to pointer

int main()
{
myclass myclass1;
firstfunc(&myclass1);
return 0;
}

void firstfunc(myclass * myclass1)
{
secondfunc(myclass1); //pass the pointer along to the second function
return;
}

void secondfunc(myclass * myclass1) //(got rid of that semi-colon  typo) - and just a pointer to myclass not a pointer to pointer 
{
std::cout << myclass1->myvar;
return;
}
Last edited on
That never occurred to me to just pass the pointer along XD!

Thank you very much
Topic archived. No new replies allowed.