Ergebnis 1 bis 6 von 6

Thema: Niji-chans 2. C\C++ Fragethread

Hybrid-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #1

    Niji-chans 2. C\C++ Fragethread

    Hi!

    Habe momentan ein Problem mit einer Headerdatei. Sie ist im gleichen Ordner wie die "*.cpp"-Datei. Folgende Fehlermeldung erhalte ich auf die unten markierte Stelle im Programmcode:

    Zitat Zitat
    5 CDokumente und Einstellungen\...\Eigene Dateien\Projekte\Programmieren\C_Cplusplus\cppin21tagen\tag6_3.cpp In file included from CDokumente und Einstellungen\...\Eigene Dateien\Projekte\Programmieren\C_Cplusplus\cppin21tagen\tag6_3.cpp
    Code:
    // Beginn von rect.cpp
    
    #include <iostream>
    using namespace std;
    #include "rect.hpp"
    
    Rectangle::Rectangle(int top, int left, int bottom, int right)
    {
                             itsTop    =     top;
                             itsLeft   =     left;
                             itsBottom =     bottom;
                             itsRight  =     right;
                             
                             itsUpperLeft.SetX(left);
                             itsUpperLeft.SetY(top);
                             
                             itsUpperRight.SetX(right);
                             itsUpperRight.SetY(top);
                             
                             itsLowerLeft.SetX(left);
                             itsLowerLeft.SetY(bottom);
                             
                             itsLowerRight.SetX(right);
                             itsLowerRight.SetY(bottom);
    }
    
    // Rechteckflaeche berechnen. Dazu Ecken bestimmen,
    // Breite und Hoehe ermitteln, dann multiplizieren.
    
    int Rectangle:GetArea() const
    {
        int Width  = itsRight - itsLeft;
        int Height = itsTop   - itsBottom;
        
        return (Width * Height);
    }
    
    int main()
    {
        // Eine lokale Rectangle-Variable initialisieren
        Rectangle MyRectangle (100, 20, 50, 80);
        
        int Area = MyRectangle.GetArea();
        
        cout << "Flaeche: " << Area << "\n";
        cout << "Obere linke X-Koordinate: ";
        cout << MyTectangle.GetUpperLeft().GetX();
        
        return 0;
    }
    Der Code ist hauptsächlich von einem Listing aus dem Buch "C++ in 21 Tagen" abgeschrieben. ...
    Dadurch, dass die Datei nicht gefunden - oder was den Fehler sonst verursacht - funktioniert natürlich momentan gar nichts.

  2. #2
    Ist die Datei rect.hpp in dem verzeichniss deines Programms ? Ich glaube das muss da drin sein .. ka =/ probiers mal, oder hast du die Datei garnicht ?

  3. #3
    Die Zeile, die du da kopiert hast, ist an sich kein Fehler, sondern nur eine Angabe, wo díe Datei, in der der Fehler liegt, includet wurde. Der eigentliche Fehler steht erst ein paar Zeilen weiter.

  4. #4
    Die Datei rect.hpp ist im selben Ordner.
    Code:
    // Headerdatei
    
    #include <iostream>
    
    class Point        //nimmt X, Y-Koordinaten auf
    {
          // Kein Konstruktor, standardkonstruktor verwenden
          public:
                 void SetX(int x) { itsX = x; }
                 void SetY(int y) { itsY = y; }
                 int GetX()const { return itsX; }
                 int GetY()const { return itsY; }
          private:
                  int itsX;
                  int itsY;
    };            // Ende der Klassendeklaration
    
    class Rechtangle
    {
          public:
                 Rectangle (int top, int left, int bottom, int right);
                 ~Rectangle () {}
                 
                 int GetTop() const { return itsTop; }
                 int GetLeft() const { return itsLeft; }
                 int GetBottom() const { return itsBottom; }
                 int GetRight() const { return itsRight; }
                 
                 Point GetUpperLeft() const { return itsUpperLeft; }
                 Point GetLowerLeft() const { return itsLowerLeft; }
                 Point GetUpperRight() const { return itsUpperRight; }
                 Point GetLowerRight() const { return itsLowerRight; }
                 
                 void SetUpperLeft(Point Location) { itsUpperLeft = Location; }
                 void SetLowerLeft(Point Location) { itsLowerLeft = Location; }
                 void SetUpperRight(Point Location) { itsUpperRight = Location; }
                 void SetLowerRight(Point Location) { itsLowerRight = Location; }
                 
                 void SetTop(int top) { itsTop = top; }
                 void SetLeft(int left) { itsLeft = left; }
                 void SetBottom(int bottom) { itsBottom = bottom; }
                 void SetRight(int right) { itsRight = right; }
                 
                 int GetArea() const;
          private:
                  Point itsUpperLeft;
                  Point itsUpperRight;
                  Point itsLowerLeft;
                  Point itsLowerRight;
                  
                  int   itsTop;
                  int   itsLeft;
                  int   itsBottom;
                  int   itsRight;
    };
    // Ende der Headerdatei
    Ist an der denn etwas falsch, oder wo ist das Problem zu suchen?
    Kann es sein, dass es am Ende so kompiliert wird, dass
    Code:
    #include <iostream>
    2x im Programm vorkommt?

  5. #5
    Eigentlich haben die Standard-Header nen Schutz gegen doppeltes includen, aber du benutzt in der Rect-Datei nirgendwo was aus iostream, von daher brauchst die sie ja nicht zu includen..

  6. #6
    Habe jetzt meine Fehler gefunden...

    Es waren zwei Tippfehler.... einmal habe ich "Rechtangle" und ein anderes mal "MyTectangle" geschrieben...

    aber thx 4 help

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •