Easy question about passing by refrence to another function
-
I created a stuct in a class and I need a function that returns the pointer to that struct. I need to be able to access the elements in the structure.
class MyClass{ struct a { char arr[10]; double dub[10]; } function that returns the pointer to struct a void returnPointer(){ return pointer?????; } } ------------------------- (From another class) MyClass::returnPointer(); a.arr[1];
Do I need to make a struct in the class that is calling the function in order to access the elements by casting the pointer to the struct? As you can see I am a bit lost on how to do this. sj -
I created a stuct in a class and I need a function that returns the pointer to that struct. I need to be able to access the elements in the structure.
class MyClass{ struct a { char arr[10]; double dub[10]; } function that returns the pointer to struct a void returnPointer(){ return pointer?????; } } ------------------------- (From another class) MyClass::returnPointer(); a.arr[1];
Do I need to make a struct in the class that is calling the function in order to access the elements by casting the pointer to the struct? As you can see I am a bit lost on how to do this. sj -
if you asking about syntax struct MyClass::a* returnPointer(){return pointer?????;} if you asking what you should return - you need to declare private/protected member of that type and return pointer to it.
Are you saying that in the class that I call the function from, I need to declare a private struct just like the one in MyClass? Then call the function and cast it to that private struct pointer? thanks, sj
-
Are you saying that in the class that I call the function from, I need to declare a private struct just like the one in MyClass? Then call the function and cast it to that private struct pointer? thanks, sj