Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning structure instead of class::structure

Status
Not open for further replies.

jmodo

Programmer
Aug 2, 2006
43
US
I have a couple classes. Class A and Class B.
class A has a structure aStruct
class B has a function that is:
A::astruct myfunction();

What is the difference if I put the A structure in the B class so that the function looks like
astruct myfunction();

does this not return an instance of a class, or what is the benefit? I am not strong in C/C++, but I am in other languages.
Thanks alot!!!
J
 
If the struct is shared by two different classes, it might be better to put the struct in a separate header file that both class headers can include.

To answer your question: there is no difference, other than the change of namespace. Now A will have to reference the struct as: B::aStruct instead of just aStruct.

It returns an instance of a struct, not a class.
The following 3 are exactly the same, other than the way you reference the struct:
Code:
aStruct myFunction();
A::aStruct myFunction();
B::aStruct myFunction();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top