Quote>How do I declear a function with in the struct?
Just to add a footnote to Wyck's excellent and comprehensive answer,
bear in mind that in C++ the only difference between a struct and a
class is that the default visibility is private in a class but is public in a struct:
class P {
int Pint;
};
struct S {
int Sint;
};
P p;
S s;
s.Sint = 0; // OK - it's public
p.Pint = 0; // No can do - it's private
Therefore the short answer to your question above is that you declare a function
in a struct the same way you do it in a class, while ensuring that public and
private are used where and as needed.
- Wayne
Just to add a footnote to Wyck's excellent and comprehensive answer,
bear in mind that in C++ the only difference between a struct and a
class is that the default visibility is private in a class but is public in a struct:
class P {
int Pint;
};
struct S {
int Sint;
};
P p;
S s;
s.Sint = 0; // OK - it's public
p.Pint = 0; // No can do - it's private
Therefore the short answer to your question above is that you declare a function
in a struct the same way you do it in a class, while ensuring that public and
private are used where and as needed.
- Wayne