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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:26:18+00:00 2026-06-01T07:26:18+00:00

I have several files which is causing a compile error, can the following be

  • 0

I have several files which is causing a compile error, can the following be done?

header1.h

class Class1{
public:
void function1(Class1 &);
};

header2.h

class Class2{
public:
void function2(Class2 &, Class1 &);
};

cpp2.cpp

#include "header2.h"
void Class2::function2(Class2 & my2Class, Class1 & my1Class){};

main.cpp

#include "header1.h"
#include "header2.h"

// functions

The error is stating that header2.h knows nothing of Class1 as a type. How can I declare an object of type Class1 in this header file, without using an include or without putting both classes in the same file (they are entirely separate and should only meet inside functions called within main)?

Thanks!

  • 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-01T07:26:19+00:00Added an answer on June 1, 2026 at 7:26 am

    You can use forward declarations:

    class Class1; //forward declare Class1
    class Class2{
    public:
    void function2(Class2 &, Class1 &);
    };
    

    Passing a parameter of a type to a function doesn’t require the type to be fully defined.

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

Sidebar

Related Questions

I have several files with code testing code (which uses a unittest class). Later
I have several large text files (30m+ lines, >1GB) which are being processed in
I have a set of zip files which contains several ieee-be encoded binary and
I have a directory containing several files, some of which have spaces in their
We have a CMS which has several thousand text/html files in it. It turns
I have a file attachment class (FileAttachment) which is used in several other classes.
I'm nearly ready to distribute my vb.net application. I have several picturebox files which
I have written a python package which consists of several .py files which contain
I have several files out on a server which my user downloads into their
I have several xml files, the names of which are stored in another xml

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.