Home > Mobile >  Error Missing Type specifer - int assumed . Note C does not support default init
Error Missing Type specifer - int assumed . Note C does not support default init

Time:05-06

In order to make two objects, Player1 and Player2, of a class Player sending and receiving messages, I implemented a blocking queue to synchronize the messages. This is the code I used:

#include <iostream>


using namespace std;

class Msg
{
public:
    Player* sender;
 };

template <typename T>
class BlockingQueue
{
public:
    void push(const T& val)
    {}

    T pop()
    {}

};

class Player
{
    BlockingQueue<Message > queue;

public:
    
    void sendMessage()
    {
    };

    void run()
    { //...... 
    }

    


};

In the Player class, I get an error indicating that Player* sender is not a member of the Message class!

And in the Message class, i get this error:

Severity    Code    Description Project File    Line    Suppression State

    Error   C4430   missing type specifier - int assumed. Note: C   does not support default-int

Can you please help me with this?

CodePudding user response:

You have to add a forward declaration of player before Message

class Player; <<<<=====
class Message
{
public:

    Player* sender ;
    std::string text;
};

see here for explanation What are forward declarations in C ?

and yes - it should be std::string

  • Related