samedi 26 mars 2016

C++ Error: Not declared in scope; Member function

I have a an error for 'Result Vector' was not declared in this scope. I am not sure of where to or how to declare this? The intention of the Result Vector is the show the result of adding the X's of vectors and the Y's of each vector and then return result_vector

#include <iostream>
#include <vector>
using namespace std;

class vector{
private:
    double x;
    double y;
public:
    //Constructor - default
    vector() : x(0), y(0) {}
    //Constructor - Custom
    vector(double xx, double yy) : x(xx), y(yy) {}
    //Get X & Y Coordinates
    double get_x() { return x;
    }
    double get_y() { return y;
    }
    //Set X & Y Coordinates
    void set_x( double xx) { x = xx;
    }
    void set_y( double yy) { y = yy;
    }
    //Adding Vectors
    vector add_vector( vector v1, vector v2){ 
        result_vector.x = v1.x + v2.x;
        result_vector.y = v1.y + v2.y;
        return result_vector; 
    }
    //Subtracting Vectorsed
    vector subtract_vector( vector v1, vector v2){
        result_vector.x = v1.x - v2.x;
        result_vector.y = v1.y - v2.y;
        return result_vector;
    }
};

int main() {
    //Default
    vector test;
    cout <<"Default \n" test.get_x().get_y() << "\n";
    //Customer
    vector test2(10, 12);
    cout <<"Custom \n" test2.get_x().get_y() << "\n";
    //Adding
    vector add = vector.add_vector(vector test1&, vector test2&);
    cout <<"Adding \n" add.get_x().get_y() <<"\n";
    //Subtracting
    vector sub = vector.subtract_vector(vector test1&, vector test2&);
    cout <<"Subtracting \n" sub.get_x().get_y() <<"\n";

    return 0;


}

Aucun commentaire:

Enregistrer un commentaire