August 2012
Intermediate to advanced
976 pages
30h 17m
English
auto or decltype for Function Pointer TypesIf we know which function(s) we want to return, we can use decltype to simplify writing a function pointer return type. For example, assume we have two functions, both of which return a string::size_type and have two const string& parameters. We can write a third function that takes a string parameter and returns a pointer to one of these two functions as follows:
string::size_type sumLength(const string&, const string&);string::size_type largerLength(const string&, const string&);// depending on the value of its string parameter,// getFcn returns a pointer to sumLength or to largerLengthdecltype(sumLength) *getFcn(const string &);
The only tricky part in declaring getFcn is to remember that when ...
Read now
Unlock full access