I had this weird thing while I was trying to avoid pointers and just create objects on the stack.

Qt Code:
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. #include <vector>
  5. #include <cstdio>
  6. using namespace std;
  7.  
  8. class Node {
  9. public:
  10. string move;
  11. int state[10];
  12. Node(const Node &p) {
  13. move = "";
  14. memcpy(state,p.state,sizeof(int)*10);
  15. }
  16. Node(){
  17. move = "";
  18. for(int i = 0;i<10;i++){
  19. state[i] = i;
  20. }
  21. }
  22. void AddNode(Node p){
  23. this->childNode.push_back(p);
  24. }
  25. Node GetChild(int i) {
  26. return childNode[i];
  27. }
  28. int GetCount() {
  29. return this->childNode.size();
  30. }
  31. protected:
  32. vector<Node> childNode;
  33. };
  34.  
  35. class Move {
  36. public:
  37. Move() {
  38.  
  39. }
  40. void run() {
  41. Node n;
  42. n.move = "A100";
  43. operate(n);
  44. }
  45.  
  46. void operate(Node &n) {
  47.  
  48. Node c(n);
  49. c.move = "B100";
  50. n.AddNode(c);
  51. cout << "Output : " << endl;
  52. Node t = n.GetChild(n.GetCount() - 1);
  53. //Node t = n.childNode[0];
  54. for(int i = 0;i<10;i++)
  55. cout << t.state[i];
  56.  
  57.  
  58. cout << endl << t.move; // doesn't display B100 ????
  59.  
  60. }
  61.  
  62. };
  63.  
  64. int main(int argc,char** argv) {
  65.  
  66. Move m;
  67. m.run();
  68. return 0;
  69. }
To copy to clipboard, switch view to plain text mode 

Here is a sample of something that I'm trying to do. My question is why isn't B100 move displayed ? Do I need an assignment operator in the Node class ? I believed push_back takes references and that the node with move value B100 should be stored in the vector. Correct state array is stored but the move string is not, any suggestions ?