| toum (169) | |
|
Yes, it would work. For the function : yes, you have to use pointers. You can also use references instead of pointers, they may be easier to use. You can find an example of a function using references in this post: http://cplusplus.com/forum/beginner/85841/#msg464917 | |
|
|
|
| asda333 (36) | |||
regarding the code
the instruction is this REPEAT 36 [ RIGHT 10 REPEAT 360 [ FORWARD .04 RIGHT 1 ] ] without brackets its REPEAT 36 RIGHT 10 REPEAT 360 FORWARD .04 RIGHT 1 so it only detects REPEAT 36 and exits the loop. also if i change it to REPEAT 36[RIGHT 10 REPEAT 360[FORWARD .04 RIGHT 1 ]] becomes without bracket REPEAT 36 RIGHT 10 REPEAT 360 FORWARD .04 RIGHT 1 and when i loop through the code and it comes to RIGHT when it prints it displays (REPEAT,36) ([RIGHT,10) how did that square bracket get there. | |||
|
Last edited on
|
|||
| toum (169) | |
| That could be because you didn't remove the brackets. | |
|
|
|
| asda333 (36) | |
|
i did i used this replace(cmd.begin(), cmd.end(), '[', ' '); replace(cmd.begin(), cmd.end(), ']', ' '); before the while loop | |
|
|
|
| asda333 (36) | |||
I thought you said the obtaining a vector within a vector would work but it doesn't
error i get is regarding the comd=command[k] which is no match for operator= in command = cmdlist.std::vector<tp, _Alloc>::operat... | |||
|
|
|||
| asda333 (36) | |
|
i am trying to send amount value to a class and have done the following: global variable vector<string> actvec; vector<float> amountvec; class Commands { public: Commands(); virtual ~Commands(); virtual void performaction(){}; protected: float amount; }; class Forward : public Commands { public: void performaction() { actvec.push_back("FORWARD"); amountvec.push_back(amount); } }; same with other commands, as that is what is required from me, to set a class for each one that inherits from the main base class. void performcommand(string commandstr, float amnt) { if(commandstr=="LEFT") { Left.amount=amnt; Left.performaction(); } else if(commandstr=="RIGHT") { Right.amount=(-amnt); Right.performaction(); } else if(commandstr=="FORWARD") { Forward.amount=amnt; Forward.performaction()); } else if(commandstr=="JUMP") { Jump.amount=amnt; Jump.performaction(); } else cout<<"The Command was not identifiable"<<endl; } but for each line it says expected unqualified-id before '.' token i don't understand | |
|
Last edited on
|
|
| asda333 (36) | |||
|
Ok so i got rid of that error somehow i don't know now i am debugging when i run this code
this prints out Performing Action:Forward Amount: 0.04 Performing Action: Right Amount:1 FORWARD 0.04 RIGHT 1 FORWARD 0.04 RIGHT 1 it print 360 of it. | |||
|
|
|||
| asda333 (36) | |
|
would you mind looking at my complete code and tell me where i am going wrong as there might be mistakes in other areas. regards | |
|
|
|
| asda333 (36) | |
|
ok i am making some progress my program draws commands that don't contain repeat commands but the ones contain repeat commands it causes a segmentation fault. | |
|
|
|
| asda333 (36) | |
|
THe main error i am getting is during the following code while( as >> action >> value ) { as << action << ' ' << value << ' '; tempcomd.push_back(as.str()); cout<<action<<","<<value<<endl; } it just goes through this forever forward 0.04 right 1 forward 0.04 right 1 and so on. | |
|
Last edited on
|
|
| asda333 (36) | |
|
i have solved that as well i placed it in a loop it would work outside and eureka it works | |
|
|
|
| asda333 (36) | |
|
the project is finally finished and all works well thanks for the help | |
|
|
|
| toum (169) | |
| You're welcome. | |
|
|
|
| asda333 (36) | |
|
just one more thing since i am moving over to linux to test this on. i have added error code if it can't find file, which when i run i get that error, linux doesn't have c:\ it does it straight from root so when i place ifstream myfile ("\\home\\C++Project\\command.txt") it still says can't find file. how can i write it so i just do istream myfile("command.txt"); because even when i write that it says file not found on current directory my error message thanks | |
|
|
|