I have C++ code different output compared to what I expected, I hope to understand how it's executed
#include <iostream>
#include <string>
int x = 8;
class A {
public :
A(){int x = 5 ;}
void print (int x = 4) { std::cout <<"the scope variable"<< ::x<<"passed variable" << x ;}
};
int main()
{
A a ;
a.print(7);
}
I expected to be 5 and 7 but the result is 8 and 7
Aucun commentaire:
Enregistrer un commentaire