initialization - Why I can use class Variable without initialize it c++ -


i have next code (make small & simple),

why did speed += working, although speed wasn't initialized @ all?

#include <iostream> using namespace std;  class vehicle {    protected:      int speed;       public:          virtual void repair(int j) {              cout << "vehicle " << j << endl;               if (repair())              {                  speed += j;                  cout << "speed:" << speed;              }         }         int repair(){ cout << "vehicle repair " << endl; return 1; } };  void main() {      vehicle v; //car c; citycar cc;     vehicle * vp; //car * cp;      vp = &v;      vp->repair(1); } 

in c++ can use uninitialized variables, @ you'll warning. except if set "warning errors" option, in case you'll error, obviously.

different compilers different things, in case, depending on compiler , compiler options, can warning, or not. see this question.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -