A few days ago I found a totally new syntax like
auto ClassName::functionName() -> something.
Then I started to find out what does it mean and got my answer. Today I am going to share this.
Lets we have a class as
what do you think? is there any problem?
Actually there is a problem. The enum Type declared inside the Class and when we will try to define the function outside the class, compiler will not found the Type there. In this case
Type Person::getType()
will cause an error.
Now there is a solution to avoid this error is to define the function inside the class. But what if you we don’t want to do that. How can we define such functions outside the class?
here comes the syntax We talked about.
auto className::functionName()->returnType
This is the feature of C++11.
in our case our function will be
auto Problem::getType() -> Type
{
return m_type;
}
Thank you.