Can we define a structure on type?
So I am looking on question about struct vs class difference... And I do not get one thing - can we define a structure on type? like tiped class... If 开发者_C百科yes please provide some samples.
If you mean, Can you use a struct much like you would use a class? the answer is yes. In C++ the only difference is the defaults for visibility. Members of a class default to private; members of a struct default to public. If you create a class and make all the members public, it's pretty much the same as a struct. I understand that compilers vary on whether a struct can inherit from a class and vice versa.
Frankly, I think struct's exist in C++ mainly for upward compatibility from C. Or to put it another way, class's only exist because that's the new name for the same idea.
精彩评论