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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:30:54+00:00 2026-06-01T09:30:54+00:00

I have a problem with operators. Generally I know basics of using operators. But

  • 0

I have a problem with operators. Generally I know basics of using operators. But my problem starts when I want to compare two objects. I have 2 different classes declaration files okrag.h and prostokat.h . I want to compare two objects from different classes:

//okrag.h   -- circle class
#ifndef __OKRAG_H__
#define __OKRAG_H__
#include "figura.h"
#include "prostokat.h"

class COkrag: public CFigura
{
    protected:
    int m_iR; 

    public:
        COkrag();
        COkrag(int x, int y, int r);
        ~COkrag();
        void ZmienR(int r);
        float PodajObwod();
        float PodajPole();  
        int PodajR();
        void operator+(int r);
        friend void operator+(COkrag o, int x[2]);


        bool operator>(COkrag o2);

        friend bool operator>(COkrag o1, CProstokat o2);

        bool operator<(COkrag o2);
        bool operator>=(COkrag o2);
        bool operator<=(COkrag o2);
        friend ostream& operator << (ostream &wy, COkrag &O);

};
#endif



//prostokat.h
#ifndef __PROSTOKAT_H__
#define __PROSTOKAT_H__
#include "figura.h"
#include "okrag.h"

class CProstokat: public CFigura
{
    protected:
    int m_iSz, m_iWy; 


    public:
        CProstokat();
        CProstokat(int x, int y, int szer, int wys);
        ~CProstokat();
        void ZmienSz(int x);
        void ZmienWy(int y);
        float PodajObwod();
        float PodajPole();
        void operator+(int a);
        friend void operator+(CProstokat p, int x[2]);

        bool operator>(CProstokat p2);
        bool operator<(CProstokat p2);
        bool operator>=(CProstokat p2);
        bool operator<=(CProstokat p2);


        friend ostream& operator << (ostream &wy, CProstokat &P);

};
#endif

My problem is when it starts compiling and and finds this line: friend bool operator>(COkrag o1, CProstokat o2);

It says: Error 1 error C2061: syntax error : identifier 'CProstokat'

I have no idea what the reason is. It looks like it doesn’t know object CProstokat but header file with declaration of this class was included.

Can anyone tell me what’s wrong?

EDIT:
I have corrected my code and here is what I get. I don’t know why I couldn’t add const to bool operator>(CProstokat & p2); I wanted it to look like this:

bool operator>(CProstokat & p2);

but compiler says

Error 3 error C2662: 'CProstokat::PodajPole' : cannot convert 'this' pointer from 'const CProstokat' to 'CProstokat &'

Now it works without it. Here is what I get.

#ifndef __OKRAG_H__
#define __OKRAG_H__
#include "figura.h"


class CProstokat;

class COkrag: public CFigura
{
    protected:
    int m_iR; 

    public:
        COkrag();
        COkrag(int x, int y, int r);
        ~COkrag();
        void ZmienR(int r);
        float PodajObwod();
        float PodajPole();  
        int PodajR();
        void operator+(int r);
        friend void operator+(COkrag o, int x[2]);




        bool operator>(const CProstokat & p2); //I have changed it because now I can use 'this->' 
        bool operator<(CProstokat & p2);
        bool operator>=(CProstokat & p2);
        bool operator<=(CProstokat & p2);

        bool operator>(COkrag o2);
        bool operator<(COkrag o2);
        bool operator>=(COkrag o2);
        bool operator<=(COkrag o2);
        friend ostream& operator << (ostream &wy, COkrag &O);

};
#endif


#ifndef __PROSTOKAT_H__
#define __PROSTOKAT_H__
#include "figura.h"


class COkrag;
class CProstokat: public CFigura
{
    protected:
    int m_iSz, m_iWy; 


    public:
        CProstokat();
        CProstokat(int x, int y, int szer, int wys);
        ~CProstokat();
        void ZmienSz(int x);
        void ZmienWy(int y);
        float PodajObwod();
        float PodajPole();
        void operator+(int a);
        friend void operator+(CProstokat p, int x[2]);

        bool operator>(COkrag& o2);
        bool operator<(COkrag& o2);
        bool operator>=(COkrag& o2);
        bool operator<=(COkrag& o2);

        bool operator>(CProstokat p2);
        bool operator<(CProstokat p2);
        bool operator>=(CProstokat p2);
        bool operator<=(CProstokat p2);


        friend ostream& operator << (ostream &wy, CProstokat &P);

};
#endif

I hope I understand Your advice correctly. Thank all of you for time spent on answering.

  • 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-01T09:30:56+00:00Added an answer on June 1, 2026 at 9:30 am

    The problem is that the header files include each other. This will result in the following scenario:

    Assume some code file includes procostat.h. Now when processing procostat.h the preprocessor will first process the include guard, defining __PROKOSTAT_H__ (side node: All identifiers containing double underscores are reserved for the implementation; don’t use them for your own code), then include figura.h, and then find and process the #include "okrag.h". In processing that file, the same will happen until the #include "prokostat.h", which instructs the compiler to again process that file (note that until that point, none of your actual code, except for the contents of figura.h, has been processed). While processing (again) that file, it will again first process the include guard, find that __PROKOSTAT_H__ is already defined, and therefore honor the #ifndef by not processing the content of the file until the corresponding #endif at the end. Then the compiler will continue to process the file okrag.g (remember: It still has not seen a single line of actual code from prokostat.h!) and come across the friend definition of operator> which uses CProkostat. But up to now, it did not see the definition of CProkrostat, therefore it complains about the undefined identifier.

    Now how to fix it? Well, the simplest fix is just noticing that prokostat.h doesn’t actually reference anything from okostat.h, therefore you just can remove the #include "okostat.h" from it. That will break the circular dependency and therefore fix the immediate problem.

    However it’s not yet the perfect fix, for two reasons: First, what if you ever need to reference COkrak in prokostat.h? And second, you’ll need to recompile every file including procostat.h whenever okrak.h changes, even if the file uses nothing from okrak.h.

    Therefore the correct fix is to not only remove the #include "okrak.h" from prokostat.h but additionally remove the #include "prokostat.h" from okrak.h and instead add a forward declaration for CProkostat at the beginning of that file (i.e. before any of its definitions). That forward declaration looks like this:

    class CProkostat;
    

    This lets the compiler know that a class of that name exists without telling any of the details (it’s called an incomplete type). You don’t need those details to declare the friend function (however you do need them to define the friend function, so in the corresponding implementation file you’ll have to #include "prokostat.h").

    As a side note, your comparison operators should take the objects by const reference, to avoid unnecessary copying.

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

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
i have problem with autorotate on iphone i set up in all classes -
I'm having a problem when trying to compile these two classes (Army and General)
I am thinking about different solutions for one problem. Assume we have K sorted
I have a problem. I have an ArrayList of objects. Each object contains a
I have following problem where I have to group different transactions into timeslots. Suppose
I have a problem when I call operator<< on a pointer. I have searched
I'm facing a problem in Xcode with the operator keyword. I have this in
I have a problem. I need to trace all read/write operations to the registry

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.