Konstruktor



  • Das sind doch oben die Fehlermeldungen ?



  • Nein, das ist das was deine IDE aus den Ausgaben macht. Suche die echte Ausgabe des Compilers.



  • 1:09:26 **** Incremental Build of configuration Debug for project CRectangle ****
    make all
    Building file: ../CRectangle.cpp
    Invoking: GCC C++ Compiler
    g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"CRectangle.d" -MT"CRectangle.d" -o "CRectangle.o" "../CRectangle.cpp"
    ../CRectangle.cpp: In constructor ‘CRectangle::CRectangle(CPoint, CPoint, char)’:
    ../CRectangle.cpp:34:15: error: ‘class CPoint’ has no member named ‘x’
    if(topRight.x < bottomLeft.x ){
    ^
    ../CRectangle.cpp:34:30: error: ‘class CPoint’ has no member named ‘x’
    if(topRight.x < bottomLeft.x ){
    ^
    ../CRectangle.cpp:36:17: error: ‘class CPoint’ has no member named ‘x’
    m_topRight.x = bottomLeft.x;
    ^
    ../CRectangle.cpp:36:32: error: ‘class CPoint’ has no member named ‘x’
    m_topRight.x = bottomLeft.x;
    ^
    ../CRectangle.cpp:39:16: error: ‘class CPoint’ has no member named ‘y’
    if(topRight.y < bottomLeft.y){
    ^
    ../CRectangle.cpp:39:31: error: ‘class CPoint’ has no member named ‘y’
    if(topRight.y < bottomLeft.y){
    ^
    ../CRectangle.cpp:41:17: error: ‘class CPoint’ has no member named ‘y’
    m_topRight.y = bottomLeft.y;
    ^
    ../CRectangle.cpp:41:32: error: ‘class CPoint’ has no member named ‘y’
    m_topRight.y = bottomLeft.y;
    ^
    make: *** [CRectangle.o] Fehler 1
    subdir.mk:27: die Regel für Ziel „CRectangle.o“ scheiterte

    21:09:26 Build Finished (took 483ms)



  • Versuch mal mit Worten zu beschreiben was die Fehlermeldung bemängelt.
    Dann sollte klar werden wo der Fehler liegt.



  • Wie kommst du auf .x bzw. .y?
    Schau dir die Klasse "CPoint" nochmal genau an...



  • In der Klasse steht es so:

    CPoint::CPoint(int x, int y) 
    { 
        m_x = x; 
        m_y = y; 
    } 
    
    void CPoint::setX(int x) 
    { 
        m_x = x; 
    } 
    
    void CPoint::setY(int y) 
    { 
        m_y = y; 
    }
    

    Ich dachte das man mit dem .x auf das x zugreift ?

    Wie soll ich es sonst machen?



  • Gast12 schrieb:

    Wie soll ich es sonst machen?

    Über die Funktionen, welche dir die Klasse CPoint anbietet, um den Wert von x bzw. y zu erhalten.



  • Habe es so versucht , aber scheint auch das problem nicht zu lösen?

    if(topRight.setX() < bottomLeft.setX() ){
    
    	    m_topRight.setX() = bottomLeft.setX();
    	  }
    


  • Ja klar, setX ist die Funktion, die den Wert x liefert. Ernsthaft? Da stehen sogar noch Kommentare dran!



  • manni66 schrieb:

    Ja klar, setX ist die Funktion, die den Wert x liefert. Ernsthaft? Da stehen sogar noch Kommentare dran!

    Das unterstütze ich! Bitte erstmal das Lesen womit man arbeitet! Ansonsten muss man das hier leider als Trollversuch einordnen.



  • #include "CRectangle.h"
    #include "CPoint.h"
    CRectangle::CRectangle(char fillChar)
    
    {
      m_fillChar = fillChar;
      /**
         * Erzeugt ein neues Rechteck mit der angegebenen linken
         * unteren und rechten oberen Ecken sowie dem angegebenen
         * F�llzeichen.
         *
         * Beim Erzeugen wird die Zusicherung �berpr�ft, dass die
         * rechte obere Ecke rechts von und oberhalt der linken
         * unteren Ecke liegen muss! Falls die x-Koordinate
         * der rechten oberen Ecke nicht gr��er als die x-Koordinate
         * der linken unteren Ecke ist, wird sie auf den Wert
         * der x-Koordinate der linken unteren Ecke gesetzt. Falls
         * die y-Koordinate der rechten oberen Ecke nicht gr��er als
         * die y-Koordinate der linken unteren Ecke ist, wird sie auf
         * dem Wert der y-Koordinate der linken unteren Ecke gesetzt.
         */
    
    }
    
    CRectangle::CRectangle(CPoint bottomLeft, CPoint topRight, char fillChar)
    {
    	m_fillChar = fillChar;
    
    	 if(topRight.getX() < bottomLeft.getX() ){
    
    	    m_topRight.setX(bottomLeft.getX());
    	  }
    
    	  if(topRight.getY() < bottomLeft.getY()){
    
    	    m_topRight.setY(bottomLeft.getY());
    	  }
    }
    
    void CRectangle::setCorners(CPoint bottomLeft, CPoint topRight)
    {
    	// Bitte implementieren
    }
    
    CPoint CRectangle::getBottomLeftCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    CPoint CRectangle::getTopRightCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    void CRectangle::setFillChar(char fillChar)
    {
    	// Bitte implementieren
    }
    
    char CRectangle::getFillChar() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return 0;
    }
    
    bool CRectangle::operator ==(const CRectangle& other) const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return false;
    }
    
    void CRectangle::draw(CScreen& screen) const
    {
    	// Bitte implementieren
    }
    

    Noch diese Fehler zu beseitigen ?
    Eclipse meckert auch nur rum. 😃

    Description Resource Path Location Type
    no matching function for call to ‘CPoint::setX()’ CRectangle.cpp
    /CRectangle line 34 C/C++ Problem
    candidate: void CPoint::setX(int) CPoint.h /CRectangle line 32 C/C++
    Problem
    candidate expects 1 argument, 0 provided CPoint.h /CRectangle line
    32 C/C++ Problem
    no matching function for call to ‘CPoint::setY()’ CRectangle.cpp
    /CRectangle line 39 C/C++ Problem
    make: *** [CRectangle.o] Fehler 1 CRectangle C/C++ Problem
    no matching function for call to ‘CPoint::setX()’ CRectangle.cpp
    /CRectangle line 36 C/C++ Problem
    die Regel für Ziel „CRectangle.o“ scheiterte subdir.mk
    /CRectangle/Debug line 27 C/C++ Problem
    candidate: void CPoint::setY(int) CPoint.h /CRectangle line 37 C/C++
    Problem
    candidate expects 1 argument, 0 provided CPoint.h /CRectangle line
    37 C/C++ Problem
    no matching function for call to ‘CPoint::setY()’ CRectangle.cpp
    /CRectangle line 41 C/C++ Problem



  • manni66 schrieb:

    Dann suchst du mal die Stelle in deiner IDE, an der man die Ausgabe des Compilers sehen kann und kopierst die komplette Meldung.



  • Building file: ../CRectangle.cpp
    Invoking: GCC C++ Compiler
    g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"CRectangle.d" -MT"CRectangle.d" -o "CRectangle.o" "../CRectangle.cpp"
    ../CRectangle.cpp: In constructor ‘CRectangle::CRectangle(CPoint, CPoint, char)’:
    ../CRectangle.cpp:34:20: error: no matching function for call to ‘CPoint::setX()’
    if(topRight.setX() < bottomLeft.setX() ){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:34:40: error: no matching function for call to ‘CPoint::setX()’
    if(topRight.setX() < bottomLeft.setX() ){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:36:22: error: no matching function for call to ‘CPoint::setX()’
    m_topRight.setX() = bottomLeft.setX();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:36:42: error: no matching function for call to ‘CPoint::setX()’
    m_topRight.setX() = bottomLeft.setX();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:32:7: note: candidate: void CPoint::setX(int)
    void setX(int x);
    ^~~~
    ../CPoint.h:32:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:39:21: error: no matching function for call to ‘CPoint::setY()’
    if(topRight.setY() < bottomLeft.setY()){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:39:41: error: no matching function for call to ‘CPoint::setY()’
    if(topRight.setY() < bottomLeft.setY()){
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:41:22: error: no matching function for call to ‘CPoint::setY()’
    m_topRight.setY() = bottomLeft.setY();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    ../CRectangle.cpp:41:42: error: no matching function for call to ‘CPoint::setY()’
    m_topRight.setY() = bottomLeft.setY();
    ^
    In file included from ../CRectangle.h:13:0,
    from ../CRectangle.cpp:8:
    ../CPoint.h:37:7: note: candidate: void CPoint::setY(int)
    void setY(int y);
    ^~~~
    ../CPoint.h:37:7: note: candidate expects 1 argument, 0 provided
    make: *** [CRectangle.o] Fehler 1
    subdir.mk:27: die Regel für Ziel „CRectangle.o“ scheiterte

    00:29:08 Build Finished (took 302ms)



  • Das ist die Stelle, die du angeblich geändert hast...



  • Jetzt klappt es ohne Fehlermeldung .

    Kann ich die Zuweisung so vor der If Bedingung machen ?

    m_fillChar = fillChar;
    m_bottomLeft = bottomLeft;
    m_topRight = topRight;

    * CRectangle.cpp
     *
     *  Created on: 05.02.2015
     *      Author: lipp
     */
    
    #include "CRectangle.h"
    #include "CPoint.h"
    CRectangle::CRectangle(char fillChar)
    
    {
      m_fillChar = fillChar;
      /**
         * Erzeugt ein neues Rechteck mit der angegebenen linken
         * unteren und rechten oberen Ecken sowie dem angegebenen
         * F�llzeichen.
         *
         * Beim Erzeugen wird die Zusicherung �berpr�ft, dass die
         * rechte obere Ecke rechts von und oberhalt der linken
         * unteren Ecke liegen muss! Falls die x-Koordinate
         * der rechten oberen Ecke nicht gr��er als die x-Koordinate
         * der linken unteren Ecke ist, wird sie auf den Wert
         * der x-Koordinate der linken unteren Ecke gesetzt. Falls
         * die y-Koordinate der rechten oberen Ecke nicht gr��er als
         * die y-Koordinate der linken unteren Ecke ist, wird sie auf
         * dem Wert der y-Koordinate der linken unteren Ecke gesetzt.
         */
    
    }
    
    CRectangle::CRectangle(CPoint bottomLeft, CPoint topRight, char fillChar)
    {
    	m_fillChar = fillChar;
    	m_bottomLeft = bottomLeft;
    	m_topRight = topRight;
    
    	 if(topRight.getX() < bottomLeft.getX() ){
    
    	    m_topRight.CPoint::setX(bottomLeft.getX());
    	  }
    
    	  if(topRight.getY() < bottomLeft.getY()){
    
    	    m_topRight.setY(bottomLeft.getY());
    	  }
    }
    
    void CRectangle::setCorners(CPoint bottomLeft, CPoint topRight)
    {
    	// Bitte implementieren
    }
    
    CPoint CRectangle::getBottomLeftCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    CPoint CRectangle::getTopRightCorner() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return CPoint();
    }
    
    void CRectangle::setFillChar(char fillChar)
    {
    	// Bitte implementieren
    }
    
    char CRectangle::getFillChar() const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return 0;
    }
    
    bool CRectangle::operator ==(const CRectangle& other) const
    {
    	// Bitte implementieren und dabei das return-Statement ersetzen.
    	return false;
    }
    
    void CRectangle::draw(CScreen& screen) const
    {
    	// Bitte implementieren
    }
    


  • Gast12 schrieb:

    Jetzt klappt es ohne Fehlermeldung .

    Kann ich die Zuweisung so vor der If Bedingung machen ?

    m_fillChar = fillChar;
    m_bottomLeft = bottomLeft;
    m_topRight = topRight;

    Technisch gesehen kannst du das machen. Ob es das ist, was du machen willst, kann ich nicht beurteilen. Am besten probierst du aus, ob das raus kommt, was du erwartest.



  • Sagen wir mal so .
    Ich übe ja an dieser Aufgabe.
    Ist es das was der Aufgabensteller erwartet ? 😃



  • Gast12 schrieb:

    Sagen wir mal so .
    Ich übe ja an dieser Aufgabe.
    Ist es das was der Aufgabensteller erwartet ? 😃

    Ich denke mal der erwartet (oder eventuell auch nicht), dass durch das Lösen der Aufgabe Verständnis für das Programmieren und die Sprache entwickelst.
    Das wird aber nicht passieren, wenn du einfach nur rätst und da irgendwas reinschreibst.
    Du musst schon die Logik dahinter verstehen und dir auch etwas dabei denken.

    Im Endeffekt drückt man beim Programmieren einen logischen Gedankengang in einer formalen Sprache aus - wenn man die Logik einfach weglässt und per trial und error + Forenposts irgendwann zum Ergebnis kommt, dann hat man aber nichts gelernt.



  • Gast12 schrieb:

    Sagen wir mal so .
    Ich übe ja an dieser Aufgabe.
    Ist es das was der Aufgabensteller erwartet ? 😃

    Kling halbwegs so. Wäre etwas einfacher zu beurteilen, wenn du kaputte Sonderzeichen in der kopierten Aufgabenbeschreibung korrigiert hättest.

    Als kleiner mathematischer Tipp

    \neg(x < y) \not\equiv x>y



  • Ist die Zusicherung von meiner Setter Methode richtig ?


Anmelden zum Antworten