0

Hi, I've been trying to create an accessor for my class that returns an array of structs as well as another that returns just a simple char array, but I can't seem to figure out how to do it, I had assumed it would just be

Example_Struct Foo::GetStructBar()
{
return structBar;
}

char Foo::GetBar()
{
return bar;
}

Where structBar is an array of structs and bar is a char array.

This does not function and I have tried searching for a solution but all I see are messy solutions involving static arrays and passing in an array as a pointer, this is an accessor for a private data member, these don't seem like very good ways to go about it.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jonsca
0

And by class I mean classes and objects, not school, just in case someone seemed to make that assumption.

0
Example_Struct * Foo::GetStructBar()
{
   return structBar;
}

char * Foo::GetBar()
{
    return bar;
}

Provided you have Example_struct structBar[10]; (your array length here obviously) and char * bar declared in your class. Make them Example_struct * and char * return variables in main also.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.