Hello. I am learning c++ from the "learning c++ by creating games in UE4" book and there is a section i am stuck on. I have copied the code from the book, it is the exact same but there is problems in it, specifically with the Player me and the me.xxxxx sections, they do not work. Can someone tell me if the book is wrong or what if they know thanks. Also like i said I have just started learning so if possible can you use dumb language for me XD
Can you elaborate on what you mean by it "not working?"
The first thing that I've noticed is that this "vector" type isn't actually defined anywhere. Also, int main() needs to return a value. Try writing return 0; right before the function's closing bracket.
main returns the value 0 if no return statement is encountered before the end of the function. Explicitly providing one is redundant. (This is only true of main.)
Well I have just got the player part to work (which i have been stuck with for over a month, im such an idiot XD) but the vector part. Where would i place the struct vector, i know if i put it under the struct player it does not work. Invalid combination of type specifiers it says.
edit
I have tried it this way aswel but it still does not work, the error is incomplete type is not allowed
#include <iostream>
#include <string>
using namespace std;
struct Player
{
string name;
float hp;
};
struct vector
{
vector position;
};
int main()
{
Player me;
me.name = "William";
me.hp = 100.0f;
me.position.x = me.position.y = me.position.z = 0;
I am just writing out the books examples, just to see how things work. But it did not teach how to do struct player and struct vector in the same code, so i just placed them together and i get the error incomplete type is not allowed. like i said, this is all brand new to me, ive never done coding before.
I'm not familiar with the book, but I can understand your frustration.
I would recommend not calling your position vector. I changed it to vector3, as it a vector in three dimensional space. There is a vector in c++, but that is something completely different from what you want.
Here's code to do what you want. Ask questions if you don't understand.