-
Inner classes
I have a .cc file with several methods in it. I also have some structs declared at the top of the file that I use inside of the .cc file. I'd like these structs to have methods, ie. I'd like the structs to be classes. Is that only a matter of replacing the word struct with class?
Currently I have:
Code:
struct A
{
int a1;
int a2;
}
I'd like to have:
Code:
class A
{
int a1;
int a2;
int add(void)
{
return a1+a2;
}
}
Is that all I have to do?
-
You can put methods inside a struct too.
-
I didn't know that. Thanks
-
In C++, a struct is a class with base classes (i.e., inheritance) and members public by default. As Stroustrup's C++ glossary entry on struct puts it, they are "most often used for data structures without member functions or class invariants, as in C-style programming".