// whats the difference between this
constint getresult() { return 13;}
// this way must be in a class for some reason
class test()
{
int getresult() const
{
return 13;
}
};
// and this
class test2()
{
constint getresult() const
{
return 13;
}
};
basically im pretty clear when const is used as a function argument but confused when either its at the start of a function or the end of a function and why does it have to be in a class to be at the end of a function.
In the case of these return values, there is no difference since you are returning an int by value. A const int can be assigned to anything, including a non-const int.
The const after the formal parameter list indicates it will not modify the calling object, and thus is suitable to be called from a const object.