Is it legal C ++ to use typedef in a method declaration, but a canonical type in a method definition?

GNU C ++ (g ++ -pedantic -Wall) accepts this:

typedef int MyInt;

class Test
{
public:
    MyInt foo();
    void bar(MyInt baz);
}; 

int Test::foo()
{
    return 10;
}

void Test::bar(int baz)
{
}

int main(void)
{
    Test t;
    t.bar(t.foo());
    return 0;
}

Is this legal C ++? Can other compilers accept it?

+3
source share
3 answers

Yes, this is legal:

7.1.3 typedef specifier

, typedef typedef-name. typedef-name , , 8. A , typedef-name . typedef , (9.1) .

+10

, , . Typedefs , , - , , .

+7

, .

, , , , .

+1

Source: https://habr.com/ru/post/1716006/


All Articles