Thread: Dev-Cpp Compliation Issues..

  1. #1
    Deaf By Pills
    Join Date
    Apr 2004
    Posts
    5

    Dev-Cpp Compliation Issues..

    In Rect.hpp

    Code:
    #ifndef Rect_H
    #define Rect_H
    // Begin Rect.h
    #include <cstdlib.h>
    #include <iostream.h>
    
    class Point{        // holds x,y coordinates
        //no constructor, using default
        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;
    };      // end of Point Class declaration
    
    class Rectangle{
        public:
            Rectangle(int top, int left, int bottom, int right);
            ~Rectangle() {}
        
            int GetTop() const {return itsTop; }
            int GetLeft() const {return itsLeft; }
            int GetRight() const {return itsRight; }
            int GetBottom() const {return itsBottom; }
        
            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 SetRight(int right) {itsRight = right; }
            void SetBottom(int bottom) {itsBottom = bottom; }
        
            int GetArea() const;
        
        private:
            Point itsUpperLeft;
            Point itsUpperRight;
            Point itsLowerLeft;
            Point itsLowerRight;
            int itsTop;
            int itsLeft;
            int itsBottom;
            int itsRight;
    };
    
    #endif /*Rect_H*/
    In main.cpp

    Code:
    #include "rect.hpp"
    
    Rectangle::Rectangle(int top, int left, int bottom, int right){
        itsTop = top;
        itsRight = right;
        itsLeft = left;
        itsBottom = bottom;
        
        itsUpperLeft.SetX(left);
        itsUpperLeft.SetY(top);
        
        itsUpperRight.SetX(right);
        itsUpperRight.SetY(top);
        
        itsLowerLeft.SetX(left);
        itsLowerLeft.SetY(bottom);
        
        itsLowerRight.SetX(right);
        itsLowerRight.SetY(bottom);
    }
    
    // compute area of rectangle by finding corners,
    // establish width and height then multiply (algebra lol)
    int Rectangle::GetArea() const{
        int Width = itsRight - itsLeft;
        int Height = itsTop - itsBottom;
        return (Width * Height);
    }
    
    int main(){
        Rectangle MyRectangle (100, 20, 50, 80);
        
        int Area = MyRectangle.GetArea();
        
        cout << "Area: " << Area << "\n";
        cout << "Upper Left X Coordinate: "; 
        cout << MyRectangle.GetUpperLeft().GetX();
        
      
        return 0;
    }
    Output from compiler:

    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "Z:\Code\6.9.cpp" -o "Z:\Code\6.9.exe" -fverbose-asm -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
    In file included from Z:/Code/6.9.cpp:2:
    Z:/Code/rect.hpp:4:21: cstdlib.h: No such file or directory
    In file included from C:/Dev-Cpp/include/c++/backward/iostream.h:31,
    from Z:/Code/rect.hpp:5,
    from Z:/Code/6.9.cpp:2:
    C:/Dev-Cpp/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
    Z:/Code/6.9.cpp: In function `int main()':
    Z:/Code/6.9.cpp:32: `Rectangle' undeclared (first use this function)
    Z:/Code/6.9.cpp:32: (Each undeclared identifier is reported only once for each
    function it appears in.)
    Z:/Code/6.9.cpp:32: parse error before `(' token
    Z:/Code/6.9.cpp:34: `MyRectangle' undeclared (first use this function)

    Execution terminated
    Basically, I already declared Rectangle -- so I don't understand why it's saying undeclared. It compiles fine in MSVC according to a friend -- so is there some sort of software glitch this compiler might have? Or do you see something wrong w/ my code?

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    cstdlib.h: No such file or directory
    take the .h off it... #include<cstdlib>

    while you're at it, take the .h off the <iostream> and learn a little about the standard namespace...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Deaf By Pills
    Join Date
    Apr 2004
    Posts
    5
    Quote Originally Posted by major_small
    take the .h off it... #include<cstdlib>

    while you're at it, take the .h off the <iostream> and learn a little about the standard namespace...

    standard namespace?

    Actually, forget #include <cstdlib> -- that's not in my header anymore. I still get the error nonetheless.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Dev-C++ uses g++ 3.2 (MinGW) by default.
    g++ happens to follow the standards more strictly than some versions of MSVC.

    Despite being outdated, cprogramming.com does have an FAQ on C++ namespaces.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Deaf By Pills
    Join Date
    Apr 2004
    Posts
    5
    Quote Originally Posted by laserlight
    Dev-C++ uses g++ 3.2 (MinGW) by default.
    g++ happens to follow the standards more strictly than some versions of MSVC.

    Despite being outdated, cprogramming.com does have an FAQ on C++ namespaces.

    Well, I understand the tutorial on using namespaces -- you group a section of classes together and save on typing?

    Utils::SomethingUseful::SomethingUseful() { void } blah whatever.

    But I'm still scratching my head over as to why this isn't compiling.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    hmm... not sure if Rectangle could be reserved by some (standard?) library or something.

    Substitute Rect for all instances of Rectangle and try.
    You'll still have to declare
    using std::cout;
    in your .cpp file though.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Deaf By Pills
    Join Date
    Apr 2004
    Posts
    5
    Quote Originally Posted by laserlight
    hmm... not sure if Rectangle could be reserved by some (standard?) library or something.

    Substitute Rect for all instances of Rectangle and try.
    You'll still have to declare
    using std::cout;
    in your .cpp file though.
    What does declaring using std::cout; do?

    How would I declare it? (Noob here)

  8. #8
    Deaf By Pills
    Join Date
    Apr 2004
    Posts
    5
    Quote Originally Posted by laserlight
    hmm... not sure if Rectangle could be reserved by some (standard?) library or something.

    Substitute Rect for all instances of Rectangle and try.
    You'll still have to declare
    using std::cout;
    in your .cpp file though.
    Looks like the substitution did the trick. I guess Rectangle is reserved by some STL *scritches head*

    You'd think they'd tell me these things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange problem with dev cpp
    By henrychan22 in forum C++ Programming
    Replies: 8
    Last Post: 06-18-2006, 11:05 AM
  2. Replies: 2
    Last Post: 04-09-2006, 07:20 PM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  4. Linker error in Dev Cpp (DX)
    By C+noob in forum Game Programming
    Replies: 2
    Last Post: 08-15-2005, 03:13 AM
  5. dev cpp documentation
    By sanchezero in forum Game Programming
    Replies: 2
    Last Post: 06-18-2002, 02:32 PM