Class Scope in C++
Every class defines its own new scope and a unique type. The declarations of the class members within the class body introduce the member names into the scope of their class. Two different classes have two different class scopes.
Even if two classes have exactly the same member list, they are different types. The members of each class are distinct from the members of any other class (or any other scope). Consider the following example :
Example
#include <iostream> using namespace std; class First { public: int firstVar; float SecondVar; }; class Second { public: int firstVar; float SecondVar; }; int main() { First f; f.firstVar = 10; f.firstVar = 20; Second s; s.firstVar = 30; s.firstVar = 40; cout << "First Class " << endl; cout << f.firstVar << " " << f.SecondVar << endl; cout << "--------" << endl; cout << "Second Class " << endl; cout << s.firstVar << " " << s.SecondVar << endl; f = s; // error: f and s have different types getchar(); return 0; }