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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:09:57+00:00 2026-06-16T19:09:57+00:00

Inside FileTwo.h #ifndef FILETWO #define FILETWO #includeFileOne.h class FileOne ; class FileTwo { public:

  • 0

Inside FileTwo.h

#ifndef FILETWO
#define FILETWO
#include"FileOne.h"
class FileOne ;
class FileTwo
{
public:
    int Test(FileOne One){
        return (One.var1+One.var2);}

    FileTwo(void);
    ~FileTwo(void);
};
#endif

Inside FileOne.h

#ifndef FILEONE
#define FILEONE
#include"FileTwo.h"
class FileTwo ;
class FileOne
{
private:
     int var1 , var2 , var3 ;
public :
    friend int FileTwo::Test(FileOne One);
    FileOne(){
        var1= 12;var2 = 24;
    }

};
#endif

Inside main.cpp

#include<iostream>
using namespace std ;
#include"FileOne.h"
#include"FileTwo.h"

int main(){
FileOne one ;
FileTo two ;
cout<<two.Test(one);
}

During compilation i got the following error

   1-- error C2027: use of undefined type 'FileOne' c:\users\e543925\documents\visual studio 2005\projects\myproject\filetwo.h
   2--error C2027: use of undefined type 'FileOne'  c:\users\e543925\documents\visual studio 2005\projects\myproject\filetwo.h  

   3--error C2228: left of '.var1' must have class/struct/union c:\users\e543925\documents\visual studio 2005\projects\myproject\filetwo.h
   4--error C2228: left of '.var2' must have class/struct/union c:\users\e543925\documents\visual studio 2005\projects\myproject\filetwo.h

I have found one workaround like definning the Test function inside FileTwo.cpp . But i want to know how the above issue can be resolved inside header file .

  • 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-16T19:09:58+00:00Added an answer on June 16, 2026 at 7:09 pm

    Your problem here is that you are including both files in each other. When your compiler goes to parse FileOne.h, it includes FileTwo.h, so it reads that, skips FileOne.h (thanks to the include guards; otherwise, you would go into an infinite loop) and tries to use class FileOne, which is not yet defined.

    In practice, this is just as if you had not included FileOne.h in FileTwo.h; you cannot call methods on One because its type (FileOne) is not yet defined. Nothing to do with friend classes. Or not yet (you will get into this problem later).

    From your code, it looks like you want to use class FileTwo to test FileOne. In this case, FileOne does not really need to know much about FileTwo, just allow it to look at its innards (aka make it a friend). So your code can boil down to:

    FileOne.h:

    #ifndef FILEONE
    #define FILEONE
    class FileOne
    {
      friend class FileTwo; // This is all FileOne needs from FileTwo
    private:
      int var1 , var2 , var3 ;
    public :
      FileOne(){
        var1= 12;var2 = 24;
      }
    };
    #endif
    

    FileTwo.h:

    #ifndef FILETWO
    #define FILETWO
    #include"FileOne.h"
    class FileTwo
    {
    public:
      int Test(FileOne One) {
        return (One.var1+One.var2);
      }
    
      FileTwo();
      ~FileTwo();
    };
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside FileThree.h #ifndef FILETHREE #define FILETHREE namespace blue{} class Filethree { public: Filethree(void); ~Filethree(void);
Inside FileTwo.h #includeiostream using namespace std ; class FileTwo{ public: FileTwo(){ cout<<constructor for;//Here want
Inside General.h #ifndef GENERAL #define GENERAL namespace counternamespace{ int upperbound; int lowerbound; } #endif
Inside Myclass.h Class Myclass { public: Myclass(); private: static int Myarray[12]; }; How to
Inside the Person Class: public Point[] endPointArray; private int scalar; private Head head; private
Inside of the onReceive(Content context, Intent intent) method of my public class MediaButtonIntentReceiver extends
Inside a function I need to test if another variable function exists and then
Inside a templated class, I found the expression, *this = NULL What does such
Inside an SWT Table I have many TableItems. I want to move one of
Inside my webpage http://www.my_web_page I have something like that: img border=0 class=borderx id=pic_15132 I

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.