A class that contains an object of structure vector2d
class Foo { public: Foo() { acceleration_force = vector2d(); //acceleration_force(); не видит конструктора вообще cout << "acc x: " << acceleration_force.x << " y: " << acceleration_force.y << endl; } private: vector2d acceleration_force; }; My vector2d structure
#ifndef VECTORS_H #define VECTORS_H struct vector2d { vector2d(float y, float x) : y(y), x(x) {} vector2d() : y(-1), x(0) {} float y, x; }; #endif /* VECTORS_H */ The output is acc x: inf y: -inf
Although the same code successfully works on ideone
Text output with ncurses function printw .
It looks like I have a problem with pointers and links, because debager shows everything correctly.
AddAcceleration function:
void AddAcceleration(vector2d direction, float value) { acceleration_force = (direction.normal()*value) * mass; } vector2d::normal() function
vector2d normal() { vector2d result(*this); result.x = result.length() / result.x; result.y = result.length() / result.y; return result; } GetForce function:
vector2d GetForce() { return acceleration_force; } vector2d::lenght :
float length() { return sqrt(y*y+x*x); } Foo class variables:
private: float mass; vector2d acceleration_force; float speed; vector2d friction; vector2d force; vector2d direction; GetMass() , GetSpeed() simple getters.
Plot of code that displays vector values:
foo = Foo(); foo.AddAcceleration(vector2d(-1,0), 2); printw("%f, %f", mov.GetForce().x, mov.GetForce().y); I also ask you to look at the classes where I overloaded the operators * and + structures of vector2d . They, too, as I understand, do not work:
vector2d operator+(const vector2d& right) const { vector2d result(*this); // Make a copy of myself. result.x += right.x; result.y += right.y; return result; } vector2d operator*(const float right) const { vector2d result(*this); result.x *= right; result.y *= right; return result; }
netbeans, the standardc++11,gcc 4.8.4. Project cleaned and recompiled, not working - Herrgottacc x: 0 y: -1. Compiler keys? - PinkTux-lncurses. It looks like I have a problem with pointers, the debager shows everything correctly - Herrgott