Hey everyone,
I'm having an issue with the simplest vector functions. I'm trying to add a Piece object to a vector, but it's data members are being changed when I do... am I missing something?
/* Piece.h */
#ifndef _PIECE_H
#define _PIECE_H
class Piece {
public:
Piece();
Piece(int r, int c);
Piece(const Piece& orig);
virtual ~Piece();
int r;
int c;
private:
};
#endif /* _PIECE_H */
#include <stdlib.h>
#include <vector>
#include <iostream>
#include "Piece.h"
using namespace std;
int main(int argc, char** argv) {
Piece a(1,2);
vector<Piece> vect;
vect.push_back(a);
cout << "Inside vector: " << vect[0].c << endl; //prints out 0 instead of 2
cout << "Outside vector: " << a.c << endl; //prints out 2 like it should
return (EXIT_SUCCESS);
}
/* Piece.cpp */
//#include "Piece.h"
Piece::Piece() {
}
Piece::Piece(int r, int c){
this->r = r;
this->c = c;
}
Piece::Piece(const Piece& orig) {
}
Piece::~Piece() {
}