Witam. Mam pytanie odnośnie poniższego kodu. Dlaczego kod w klasie Base który został przeze mnie wykomentowany powoduje że funkcja printf wyrzuca losowe wartości s.x oraz s.y .
#include <iostream>
using namespace std;
struct SomeS
{
int x;
int y;
SomeS() : x(0), y(0) {};
SomeS(int x, int y ) : x(x),y(y) {};
};
class Base
{
protected:
SomeS s;
int whatever;
public:
Base(const SomeS &s,int whatever): /*s(s),*/ whatever(whatever){};
void print()
{
printf("s.x=%d \n", s.x);
printf("s.y=%d \n", s.y);
printf("whatever=%d \n", whatever);
};
};
class Derived: public Base
{
public:
Derived(int whatever) : Base(s,whatever) {};
};
int main()
{
Derived C(4);
C.print();
return 0;
}