1

I'm currently doing a task in a book but I seem to struggle with creating an Instance. I'll give you the quick version of my code. Also, I'm new here, therfore I'm sorry in advance for any errors in etiquette.

#include <iostream>
using namespace std;

class CShip
{
private:
int m_xPos;
int m_yPos;
int m_Energy;

public:
CShip();
}

// Constructor

CShip::CShip
{
m_xPos = 0;
m_yPos = 0;
m_Energy = 0;
}

int main()
{
// Pointer for the object
CShip *pPlayer = NULL;

// Create Instance on the Heap
// My problem: "Player" is marked as an error...';' was expected but every semicolon was set
pPlayer = new CShip Player;

return 0;
}
trincot
  • 317,000
  • 35
  • 244
  • 286
ChunkyCrow
  • 11
  • 1
  • 1
    `pPlayer = new CShip Player;` should be `pPlayer = new CShip;` With that said I am sure what you wanted with the use of `Player` since `Player` is not defined in the code above. – drescherjm May 01 '17 at 17:03
  • 1
    By the way there's no reason here to separate the declaration of the pointer and the initialization. Also since C++11 `nullptr` should be preferred over `NULL` – UnholySheep May 01 '17 at 17:06
  • Ohh, thank you so much. Yeah, it makes more sense to me now. And I suppose, I'm using a rather outdated book then because I was tought to initialize a pointer with NULL. – ChunkyCrow May 01 '17 at 17:10
  • 2
    http://stackoverflow.com/questions/1282295/what-exactly-is-nullptr – drescherjm May 01 '17 at 17:14

0 Answers0