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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:32:28+00:00 2026-05-13T15:32:28+00:00

I have two classes declared as below: class User { public: MyMessageBox dataMsgBox; };

  • 0

I have two classes declared as below:

class User
{
public:
  MyMessageBox dataMsgBox;
};

class MyMessageBox
{
public:
  void sendMessage(Message *msg, User *recvr);
  Message receiveMessage();
  vector<Message> *dataMessageList;
};

When I try to compile it using gcc, it gives the following error:

MyMessageBox does not name a type

  • 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-05-13T15:32:29+00:00Added an answer on May 13, 2026 at 3:32 pm

    When the compiler compiles the class User and gets to the MyMessageBox line, MyMessageBox has not yet been defined. The compiler has no idea MyMessageBox exists, so cannot understand the meaning of your class member.

    You need to make sure MyMessageBox is defined before you use it as a member. This is solved by reversing the definition order. However, you have a cyclic dependency: if you move MyMessageBox above User, then in the definition of MyMessageBox the name User won’t be defined!

    What you can do is forward declare User; that is, declare it but don’t define it. During compilation, a type that is declared but not defined is called an incomplete type.
    Consider the simpler example:

    struct foo; // foo is *declared* to be a struct, but that struct is not yet defined
    
    struct bar
    {
        // this is okay, it's just a pointer;
        // we can point to something without knowing how that something is defined
        foo* fp; 
    
        // likewise, we can form a reference to it
        void some_func(foo& fr);
    
        // but this would be an error, as before, because it requires a definition
        /* foo fooMember; */
    };
    
    struct foo // okay, now define foo!
    {
        int fooInt;
        double fooDouble;
    };
    
    void bar::some_func(foo& fr)
    {
        // now that foo is defined, we can read that reference:
        fr.fooInt = 111605;
        fr.foDouble = 123.456;
    }
    

    By forward declaring User, MyMessageBox can still form a pointer or reference to it:

    class User; // let the compiler know such a class will be defined
    
    class MyMessageBox
    {
    public:
        // this is ok, no definitions needed yet for User (or Message)
        void sendMessage(Message *msg, User *recvr); 
    
        Message receiveMessage();
        vector<Message>* dataMessageList;
    };
    
    class User
    {
    public:
        // also ok, since it's now defined
        MyMessageBox dataMsgBox;
    };
    

    You cannot do this the other way around: as mentioned, a class member needs to have a definition. (The reason is that the compiler needs to know how much memory User takes up, and to know that it needs to know the size of its members.) If you were to say:

    class MyMessageBox;
    
    class User
    {
    public:
        // size not available! it's an incomplete type
        MyMessageBox dataMsgBox;
    };
    

    It wouldn’t work, since it doesn’t know the size yet.


    On a side note, this function:

     void sendMessage(Message *msg, User *recvr);
    

    Probably shouldn’t take either of those by pointer. You can’t send a message without a message, nor can you send a message without a user to send it to. And both of those situations are expressible by passing null as an argument to either parameter (null is a perfectly valid pointer value!)

    Rather, use a reference (possibly const):

     void sendMessage(const Message& msg, User& recvr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 435k
  • Answers 435k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I realize this doesn't address your question exactly, but in… May 15, 2026 at 3:44 pm
  • Editorial Team
    Editorial Team added an answer This is just a generic tree. Maybe because binary trees… May 15, 2026 at 3:44 pm
  • Editorial Team
    Editorial Team added an answer Strangely enough, the error was the result of setting the… May 15, 2026 at 3:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.