I was trying to convince a friend that struct
is just a class
in the modern C++. After a lot of arguing and resource exchange (including some SO Q&A), I came into an idea to prove it through code, so I wrote:
class A {};
struct B {};
int main()
{
cout << (is_class<A>::value ? "Yes" : "No") << "\n"; // output Yes
cout << (is_class<B>::value ? "Yes" : "No") << "\n"; // output Yes
cout << (is_same<A,B>::value ? "Yes" : "No") << "\n"; // output No ???
}
As you can see, I was surprised from the third cout
line output. So, I am stuck here now, and I do not know if am I right or not.
Is a struct
a class
or not?
Why does the code show two different things?
Update:
I pretty understand what is the difference between struct and class. What confused me is the difference between the is_class
and is_same
as answers showed. What should I have done if not asking here???
What is this site for? Why some users tend to claim questions are not useful without even put a comment to specify where it is not conforming with the asking policy?
Remember, We not all people speaks English fluently. and not all people have years of the experience.
Thanks for all who answer or comment.