Can we describe functions in a struct? For example, is this code valid?
struct function {
int func() { return 5; }
};
Can we describe functions in a struct? For example, is this code valid?
struct function {
int func() { return 5; }
};
Yes, all of the current compilers support it. Some basic struct use
And the only difference default visibility
Yes, the only differences between a struct and class in C++ are:
In C++, a structure is a class defined with the struct keyword. Its members and base classes are public by default. A class defined with the class keyword has private members and base classes by default. This is the only difference between structs and classes in C++.
Yes, it is totally part of the standard.
A struct is a class with all its members public by default.
Yes, you can, the difference to class is the access limitations to its members and methods. The struct has all its members and methods public by default.
Yes. There is no functional difference between a class and a struct, and anything you can do with one (such as defining a member function), you can do with the other.
If you're interested, the only difference is that members and base classes are private by default in a class, and public by default in a struct.