Constructor not called c++ -
i have code in dll:
game::game(int width, int height) : world(width, height), renderer("game", 800, 600), font(), text(), keyboard() { // code }
keyboard
pointer keyboard object. code inside constructor called, keyboard object remains null. why object not being created?
the keyboard constructor:
keyboard() { = new key('a'); b = new key('b'); c = new key('c'); d = new key('d'); e = new key('e'); f = new key('f'); g = new key('g'); h = new key('h'); = new key('i'); j = new key('j'); k = new key('k'); l = new key('l'); m = new key('m'); n = new key('n'); o = new key('o'); p = new key('p'); q = new key('q'); r = new key('r'); s = new key('s'); t = new key('t'); u = new key('u'); v = new key('v'); w = new key('w'); x = new key('x'); y = new key('y'); z = new key('z'); 0 = new key('0'); 1 = new key('1'); 2 = new key('2'); 3 = new key('3'); 4 = new key('4'); 5 = new key('5'); 6 = new key('6'); 7 = new key('7'); 8 = new key('8'); 9 = new key('9'); arrow_up = new key(' '); arrow_down = new key(' '); arrow_left = new key(' '); arrow_right = new key(' '); shift = new key(' '); }
how cause keyboard constructor called?
if keyboard
pointer syntax should be
game::game(int width, int height) : world(width, height), renderer("game", 800, 600), keyboard(new keyboard) { ... }
the same should done text
/font
if they're pointers.
i don't want offend you, quite basic question how pointers/instances work in c++. if you're learning c++ writing , trying code before reading language please consider investing time on reading first instead.
the reason c++ horrible language learn experimentation 2 main reasons:
not logical. of c++ rules consequence of evolution of language , of committee decisions. obvious answer problem not correct 1 in c++. way know language read it.
the language main philosophy programmers never make mistakes. in other languages when make mistake "runtime error angel" stops program , tells went wrong. in c++ instead when make mistake "undefined behavior daemon" takes legal ownership of code , try hard cause possible damage, example making program running anyway silently , nicely while until decide show someone, , crashing @ point.
the mix 1 + 2 dangerous: language complex , not told mistakes. favor instead , read first a c++ book cover cover.
Comments
Post a Comment