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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.