Access to an external structure with the same name

Take a look at my sample code

struct A
{
   int member;
};

int main()
{
   int A; //Line 1
   A b;   //Line 2 
   b.member = int(); //Line 3
}

Mistakes

prog.cpp: In function ‘int main()’:
prog.cpp:9: error: expected `;' before ‘b’
prog.cpp:9: warning: statement has no effect
prog.cpp:10: error: ‘b’ was not declared in this scope

How to access structure A in the second line? Why am I still getting a message?

+3
source share
1 answer

How to remove the error in line 2?

Use the specified type specifier, i.e. instead of writing A b;write struct A b;.

3.4.4 Specific Type Specifiers

, - (3.3.7), , .


?

A main main int A. struct A - .

3.3.7

2) (9.1) (7.2) , , . , ( ) , , , , .

+5

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


All Articles