dimanche 28 octobre 2018

When i try to access size it shows 0 and not filled

    class Rectangle{
    double m_width;
    double m_height;
    double m_initial_x;
    double m_initial_y;
    vector<double> coord_x;
    vector<double> coord_y;
public:
    Rectangle(double width = 0, double height = 0, double initial_x = 0, double initial_y = 0):
    m_width(width), m_height(height), m_initial_x(initial_x), m_initial_y(initial_y){
    }
    inline double getWidth() const{return m_width;}
    inline double getHeight() const{return m_height;}
    inline double getInitX() const{return m_initial_x;}
    inline double getInitY() const{return m_initial_y;}
    inline vector<double> &getX() { return coord_x; }
    inline vector<double> &getY() { return coord_y; }  
    void setWidth(double newWidth){
        m_width = newWidth;
    }
    void setHeight(double newHeight){
        m_height = newHeight;
    }
    void setInitX(double newInitX){
        m_initial_x = newInitX;
    }
    void setInitY(double newInitY){
        m_initial_y = newInitY;
    }
    void input(){
        cout << "width: ";
        cin >> m_width;
        cout << "height: ";
        cin >> m_height;
    }
    void draw(ofstream &myFile){
        for(int i = 0; i < coord_x.size(); i++){
            myFile << "<rect x=\"" << coord_x[i] << "\"" << " y=\"" << coord_y[i] << "\" "<< "width=\"" << getWidth() << "\" " << "height=\"" << getHeight() << "\" " << "fill=\"red\" stroke=\"white\"/>" << endl;
        }
    }
};

I have a class that place small rectangles. I tried to store coordinates in a vector. I can fill vector outside class and it really fill even i can show it's size. But when i try to write coordinates to a file, nothing happening. And when i try to see vector size. it's showing 0. I'm sure vector filling but outside filling part it's dying. How can i solve this problem?

Aucun commentaire:

Enregistrer un commentaire