Say I have the following code:
struct date {
int day;
int month;
int year;
};
class mydateclass {
public:
int day;
int month;
int year;
};
mydateclass date;
date.day;
Which date variable is being referred to? The date instance named mydateclass, or the date struct?
The struct declaration is called “date”. There is no object date created before
mydateclass date;. Therefore, the “call” is not ambigeous.If you want to create an object in that fashion it would be:
If you would do that, your compiler should complain at
mydateclass date;, as an object of that name already exists.Note that if you want to deal with the member (e.g. static member) of a class/struct w/o having an object at hands, you need :: instead of . Such as: