A new look into classes in C++

In C, when you define a struct

struct A {};

You must reference it by struct A, unless you do

typedef struct A A;

C++ automatically adds such typedef after struct’s, class’es and enum’s

struct A {};
A var; // OK

The exception is if this typedef may conflict with another name, for example, a function name:

class A {}; // typedef was not added
int A(); 

In this case, like in C, you must use the complete name:

A obj1; // ERROR
class A obj2; // OK

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s