Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ! Anytime i want to compile i get error message (C++ forbides comparisons between pointers and integers; RecordLu used but not defined ).Why ?

C++
<pre>#include <iostream>
#include <array>

 using namespace std;
    class Punkt {
        public: int XYCoord [2]={};
        void setupCoord (int x, int y){
            XYCoord[0]=x;
            XYCoord[1]=y;
        }
    };
    class Rechteck {
        public: Punkt ReCoordLu,ReCoordRo;

        double flaeche(double x, double y){
            double xy=x*y;
            return xy;
            }
        bool contains ( Punkt &p){
            Punkt *ConTemp1=&p;
            Punkt ConTemp ;
            ConTemp = *ConTemp1;

            if (ConTemp.XYCoord[0]>=&&ReCoordLu.XYCoord[0]&&ConTemp.XYCoord[1]<=ReCoordRo.XYCoord[1]){
                return true;}
            else{
                return false;}
                };
        bool contains (Rechteck &){
            if (1){
                return true;}
            else
                return false;
            }
        };
int main()
{/* Rechteck sharedRectangle (Rechteck a , Rechteck b){
            Rechteck c;
            return Rechteck c;
            } */

        Punkt P1,P2;
        P1.setupCoord(1,1);
        P2.setupCoord(5,5);
        Rechteck Rechteck1;
        Rechteck1.ReCoordLu.setupCoord(3,3);
        Rechteck1.ReCoordRo.setupCoord(9,9);

        cout<<"hello"<<P2.XYCoord[0]<<Rechteck1.ReCoordLu.XYCoord[0]<<Rechteck1.flaeche(5,5);

        return 0;};


What I have tried:

made Punkt ReCordLu public for function contain to recognize it. Revised code but cant find problem.
Posted
Updated 10-Mar-17 6:46am

The error message contains a line number. So have a look at that line:
if (ConTemp.XYCoord[0]>=&&ReCoordLu.XYCoord[0]&&ConTemp.XYCoord[1]<=ReCoordRo.XYCoord[1])

Do you see it now? It must be
if (ConTemp.XYCoord[0]>=ReCoordLu.XYCoord[0]&&ConTemp.XYCoord[1]<=ReCoordRo.XYCoord[1])

The two && are treated as address of operators here which are pointers.
 
Share this answer
 
v2
Okay thx now i it working, but i dont understand why P4(3,7)is giving returnvalue true (1) , since here 7(ConTemp.XYCoord[1]) is bigger than 5 (ReCoordRo.XYCoord[1]) ?

C++
<pre>#include <iostream>
#include <array>

 using namespace std;
    class Punkt {
        public: int XYCoord [2]={};
        void setupCoord (int x, int y){
            XYCoord[0]=x;
            XYCoord[1]=y;
        }
    };
    class Rechteck {
        public: Punkt ReCoordLu,ReCoordRo;

        double flaeche(double x, double y){
            double xy=x*y;
            return xy;
            }
        bool contains ( Punkt &p){
            Punkt *ConTemp1=&p;
            Punkt ConTemp ;
            ConTemp = *ConTemp1;

            if (ConTemp.XYCoord[0]>=ReCoordLu.XYCoord[0]&&ConTemp.XYCoord[1]<=ReCoordRo.XYCoord[1]){
                return true;}
            else{
                return false;}
                };
        bool contains (Rechteck &){
            if (1){
                return true;}
            else
                return false;
            }
        };
int main()
{/* Rechteck sharedRectangle (Rechteck a , Rechteck b){
            Rechteck c;
            return Rechteck c;
            } */

        Punkt P1,P2,P3,P4;
        P1.setupCoord(1,1);
        P2.setupCoord(5,5);
        P3.setupCoord(3,3);
        P4.setupCoord(3,7);
        Rechteck Rechteck1;
        Rechteck1.ReCoordLu.setupCoord(3,3);
        Rechteck1.ReCoordRo.setupCoord(9,9);


        cout<<"hello"<<P2.XYCoord[0]<<Rechteck1.ReCoordLu.XYCoord[0]
        <<Rechteck1.flaeche(5,5)<<Rechteck1.contains(P4) ;

        return 0;};
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900