'c++: request for member [function] in [class], which is of non-class type [class]
while trying to compile this:
class DateTime
{
private:
Date d8;
Time tym;
public:
DateTime(Date idate=Date(),Time itime=Time())
{
d8=idate;
tym=itime;
}
void set(Date idate,Time itime)
{
d8=idate;
tym=itime;
}
Time get_time()
{
return tym;
}
Date get_date()
{
return d8;
}
DateTime operator =(DateTime dt2())
{
DateTime x(dt2.get_date(),dt2.get_time());
return x;
}
};
it will return the following error in the compiler :
266:19: error: request for member ‘get_date’ in ‘dt2’, which is of non-class type ‘DateTime (*)()’
BTW i don't event know what does the error mean.
Solution 1:[1]
In assignment operator you should return a reference to the same object:
DateTime & operator= (DateTime & dt2) // without () after dt2
{
d8 = dt2.get_date();
tym = dt2.get_time();
return *this;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Manuel |