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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:28:46+00:00 2026-05-20T22:28:46+00:00

this maybe a little trivial but I’m puzzled with such problem. I want to

  • 0

this maybe a little trivial but I’m puzzled with such problem.

I want to create two classes Class1, Class2. Both classes should contain a field that contains pointer to instance of the other class. So they should be cross linked.

If I do it like this then I get an error from the compiller saying:
– ISO C++ forbids declaration of ‘Class1’ with no type
– expected ‘;’ before * token

Please help 🙂

file: class1.h

#ifndef CLASS1_H
#define CLASS1_H

#include "class2.h"

class Class1 {
public:
    Class1();
private:
    Class2* link;
}

#endif

file: class2.h

#ifndef CLASS2_H
#define CLASS2_H

#include "class1.h"

class Class2 {
public:
    Class2();
private:
    Class1* link;
}

#endif
  • 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-20T22:28:47+00:00Added an answer on May 20, 2026 at 10:28 pm

    Add class declaration (as opposed to definition) before you use it. For example, you could have:

    #ifndef CLASS1_H
    #define CLASS1_H
    
    class Class2;
    
    class Class1
    {
    public:
        Class1();
    private:
        Class2* link;
    }
    
    #endif
    

    and do the same for Class2.h.

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

Sidebar

Related Questions

Maybe this sounds a little bit crazy, but I need to come up with
This problem may be a little broad, but I'm going to go ahead and
maybe this is just a little misunderstanding but how can a programming language be
maybe this question is a little silly, but is it possible to load multiple
Maybe this is a little unconventional question but I'd like to hear an answer
The question maybe a little confusing, but it's hard to make clear this question
Maybe this question is a little far-fetched but i'll give it a shot.. Can
maybe this question is a little too general but maybe someone has experience the
maybe this question is a little basic, but I'm reading the official docs in
Maybe this is the dumbest question ever, but I'm having a little trouble getting

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.