Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:53:08+00:00 2026-06-01T09:53:08+00:00

I have a Snake class, which has a pointer to a Controller class object.

  • 0

I have a Snake class, which has a pointer to a Controller class object. This pointer will be assigned some new data, an object that is a derived from controller (eg AIController), at runtime.

I need Controller objects to be passed a pointer to Snake when they are constructed so that i can call Snake Getters/Setters within the controller class.

On the line, in the Snake constructor, flagged in the snippet below i get the following errors:

In constructor 'Snake::Snake()':|
error: expected type-specifier before 'PlayerController'|
error: cannot convert 'int*' to 'Controller*' in assignment|
error: expected ';' before 'PlayerController'|

Snippet:

Snake::Snake() : _xVelocity(0), _yVelocity(0)
{
   _controller = new PlayerController(this);
   Initialise();
}

Snake is defined like this:

class Controller;

class Snake
{
   public:
      Snake();
      virtual ~Snake();
...

   private:
      ...
      Controller* _controller;


};

Controller like this:

#include "Snake.hpp"

class Controller
{
     public:
         Controller(Snake* s);
         ~Controller();


     protected:
         ...
         Snake* _s;
};

and PlayerController like this:

#include "Controller.hpp"

class PlayerController : public prg::IKeyEvent, public Controller
{
     public:
         PlayerController(Snake* s);
         ~PlayerController();


     private:
         virtual bool onKey (const prg::IKeyEvent::KeyEvent& key);

};

I’m not certain that my attempt use a pointer to a controller object so that i can allocate the snake different controllers at runtime is correct and i know that somethings not quite right with my use of forward declaration. I appreciate the initial responses and hope that providing the errors will allow you to give me some more information. I will continue to attempt to clean up the problem so that i can properly understand the compilation process but in the mean time i’d really appreciate any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:53:09+00:00Added an answer on June 1, 2026 at 9:53 am

    Put the forward declarations in the header it is needed not before including the header. If you put it before including the header, you have to do it each time before you include the headers.

    Another thing that seems to be missing here is the duplicate inclusion guards (either with #ifndef or with #pragma once).

    In the future it is best to put here the actual errors you are encountering (the compiler’s error messages).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input which is of this form: (((lady-in-water . 1.25) (snake .
I have a class named InvoiceLine which has the following properties. public class InvoiceLine
I have a custom dll, which has a class in it, and (for simplicity's
Let's say I have a class that implements the IDisposable interface. Something like this:
I have an application which has 5 tabs on a TabBarController. For simplicity sake
I have an unordered list which contains several items called 'oListItems' the UL has
I have a class, A , in C++/CLI which derives from a templated base
For example sake, I'll use some dummy code. I have some jQuery setup that
The situation is as follows: I have a ViewModel that has a property that's
I have a method that queues some work to be executed asynchronously. I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.