Whats wrong withm_player?

Garrett Tiller 6 Reputation points
2023-06-12T04:31:10.5066667+00:00

In the initialize method of gameplay.cpp

   //New   ----------------------- 
    m_player = new Player();
    m_player->m_direction(-1, 0, 0, 0);
    m_player->m_position(0, 10.0f, 1, 0);
    m_player->lhw = (DirectX::SimpleMath::Vector3(.5, 1.0f, .5f);
    m_player->taser;

    for (int i = 0; i < 1; i++)
    {
        Enemy *m_enemy = new Enemy(DirectX::SimpleMath::Vector3(0.0f, -1.3f, 4.0f), 0.2f);
        m_enemy->Scale(DirectX::SimpleMath::Vector3(.007, .008, .007));
        //enem->pos =  Vector3( i*2,1.f,i);
        m_enemy->m_position = DirectX::SimpleMath::Vector3(i * 2, 1.f, i + 5);
        m_enemies.push_back(m_enemy);
    }

m_player witth m_position and m_direction has this error:

Error (active) E0980 call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type UnderSiege

Now I setup player.cpp to have m_position and m_direction

Player::Player(DirectX::SimpleMath::Vector3 m_position, DirectX::SimpleMath::Vector3 m_direction, DirectX::SimpleMath::Vector3 radius)
{
	Player();
	this->m_position = m_position;
	this->m_direction = m_direction;
}
Windows development Windows API - Win32
Developer technologies C++
{count} votes

1 answer

Sort by: Most helpful
  1. Giovanni Dicanio 160 Reputation points
    2023-06-12T16:21:53.9733333+00:00

    You can try and change the m_direction and m_position lines in the following code:

    m_player = new Player();
    m_player->m_direction(-1, 0, 0, 0);
    m_player->m_position(0, 10.0f, 1, 0);
    

    as this:

    m_player->m_direction = DirectX::SimpleMath::Vector3(-1.0f, 0.0f, 0.0f, 0.0f);
    m_player->m_position = DirectX::SimpleMath::Vector3(0.0f, 10.0f, 1.0f, 0.0f);
    

    Basically you should invoke the constructor for DirectX::SimpleMath::Vector3 to build the vector objects you want to assign.

    Here I am assuming that you can access the m_direction and m_position fields, for example that is possible if they are public fields.

    As an alternative, if you have defined a proper Player constructor that takes these vectors as input parameters, you can simply do something like:

    m_player = new Player( DirectX::SimpleMath::Vector3(...), 
                           DirectX::SimpleMath::Vector3(...) );
    

    Note also that in C++ it's idiomatic to create objects on the stack instead of dynamically allocate them on the heap using new. In other words: C++ is not Java.

    I don't know the rest of your code, but please make sure that you have a good reason to use new in the above case (and pay attention to properly delete the Player object you allocated with new). If you do need some form of dynamic allocation, a proper smart pointer like std::unique_ptr and its std::make_unique helper can come in handy.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.