I'm confused by the following piece of code:
#include <iostream>
using namespace std;
int *foo()
{
//Operation
}
int main ()
{
auto int ret = foo();
}
I compiled the above code under GCC, but I got the following error:
error: two or more data types in declaration of 'ret'
auto int ret = foo();
But, if I remove int
type, like so:
auto ret = foo();
then it runs successfully.
auto
is a storage class and int
is a data type, then why do I get the error "two or more data types" in the first case?
auto
as a storage-class specifier in the wild. I think that's why people accepted it could be re-purposed. Anyway now (C++11 on) it meansauto
matically deduce type and it's awesome. – Lobbyism