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 8678919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:50:34+00:00 2026-06-12T20:50:34+00:00

I have a class MotionDirection with static members. The source code of the class

  • 0

I have a class MotionDirection with static members. The source code of the class is below. But I just can not initialize the static members of the class and I can get the reason. So the problem is in the MotionDirection.cpp, see the comments for the details about the compiler errors.

MotionDirection.h

#ifndef MOTION_DIRECTION
#define MOTION_DIRECTION

namespace game{
    class IntPosition;

    class MotionDirection {
        private:
        IntPosition* positionDisplacement;
        float angle;
        MotionDirection* returnDirection;

        public:
        MotionDirection( IntPosition* positionDisplacement, float angle );
        void setReturnDirection ( MotionDirection* returnDirection );

        IntPosition* getPositionDisplacement();
        float getAngle();
        MotionDirection* getReturnDirection();

        static MotionDirection* NONE;
        static MotionDirection* LEFT;
        static MotionDirection* RIGHT;
        static MotionDirection* UP;
        static MotionDirection* DOWN;

        static void initStatics();
    };
}

#endif 

MotionDirection.cpp

#include "MotionDirection.h"
#include "IntPosition.h"

namespace game{
    MotionDirection::NONE = new MotionDirection ( new IntPosition( 0, 0),   0.0f );
    // here I get an error:
    // MotionDirection.cpp:10:5: error: 'NONE' in 'class game::MotionDirection' does not name a type

    MotionDirection::MotionDirection( IntPosition* positionDisplacement, float angle ) {
        this->positionDisplacement = positionDisplacement;
        this->angle = angle;
    }

    void MotionDirection::setReturnDirection ( MotionDirection* returnDirection ) {
        this->returnDirection = returnDirection;
    }

    IntPosition* MotionDirection::getPositionDisplacement() {
        return positionDisplacement;
    }

    float MotionDirection::getAngle() {
        return angle;
    }

    MotionDirection* MotionDirection::getReturnDirection() {
        return returnDirection;
    }

    void MotionDirection::initStatics () {
        MotionDirection::NONE  = new MotionDirection ( new IntPosition( 0, 0),   0.0f );
        MotionDirection::LEFT  = new MotionDirection ( new IntPosition(-1, 0), 180.0f );
        MotionDirection::RIGHT = new MotionDirection ( new IntPosition( 1, 0),   0.0f );
        MotionDirection::UP    = new MotionDirection ( new IntPosition( 0,-1),  90.0f );
        MotionDirection::DOWN  = new MotionDirection ( new IntPosition( 0, 1), 270.0f );
    }

    MotionDirection::initStatics();
    // or here I get an error:
    // MotionDirection.cpp:45:35: error: expected constructor, destructor, or type conversion before ';' token

}

P.S. This is Android-NDK project, I run compilation from the cygwin console.

  • 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-12T20:50:38+00:00Added an answer on June 12, 2026 at 8:50 pm

    First error

    Just replace

    MotionDirection::NONE = new MotionDirection ( new IntPosition( 0, 0),   0.0f );
    

    with

    MotionDirection* MotionDirection::NONE = new MotionDirection ( new IntPosition( 0, 0),   0.0f );
    

    Note MotionDirection* type before name of the variable: you need to provide compiler with a type.

    Second error

    You can’t put expressions out of function blocks. There are two ways to do this “right”:

    1.

    • Make initStatics() return value.
    • Add private static variable.
    • Initialize new static variable by assigning value of initStatics() to it.

    2.

    • Add nested class.
    • Write call to initStatics() in its constructor.
    • Add private static variable of that nested class.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class that I believe should not be a singleton or static class.
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have class like this below shown. which contains the shopping items where the
I have class with main method just to print Hello World when trying to
I have class GUI so I can create object like this: GUI g1 =
I have class instantiated in a web service that, in a static member, holds
I have class that extends BroadcastReceiver and gets all new sms. When I get
I have class X and in it there is a static method called doStuff()
I have class MyForm which inherited from QMainWindow . Here's my code: std::auto_ptr<MyForm> pForm(new
I have class which calls a static class, the static class basically is wrapper

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.