Thread: what to fix?simple rectangle

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    1

    what to fix?simple rectangle

    Code:
    h:
    #include <cstdlib>
    #include <iostream>
    class rectangle{
          int x,y;  
          rectangle(){
                      x=0;y=0;            
          }    
          public void v(){
                 cout<<"dsdsd"<<endl;       
          }
    };
    cpp:
     #include <cstdlib>
    #include <iostream>
    #include "rectangle.h"
    using namespace std;
    int main(int argc, char *argv[])
    {
        rectangle r;
        cout<<r.v()<<endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    error:
    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\Makefile.win"
    Executing  make...
    make.exe -f "C:\Dev-Cpp\Makefile.win" all
    g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   
    
    In file included from main.cpp:3:
    rectangle.h:9: error: expected `:' before "void"
    
    rectangle.h: In member function `void rectangle::v()':
    rectangle.h:10: error: `cout' undeclared (first use this function)
    rectangle.h:10: error: (Each undeclared identifier is reported only once for each function it appears in.)
    rectangle.h:10: error: `endl' undeclared (first use this function)
    rectangle.h: In function `int main(int, char**)':
    rectangle.h:6: error: `rectangle::rectangle()' is private
    main.cpp:7: error: within this context
    main.cpp:8: error: `cout' undeclared (first use this function)
    main.cpp:8: error: `endl' undeclared (first use this function)
    
    make.exe: *** [main.o] Error 1
    
    Execution terminated

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    call r.v() by itself amd everything should be fine. You stuck it in the IO stream, which is wrong because it never returns a value to the stream in the first place but tries to use the stream despite this.

    Or you could rewrite it I guess:
    Code:
    public:
    const char *v() {
        return "dsfdsfsds";
    }
    Also, C++ is not Java. Declare one public: field and put everything under it that's public.
    Last edited by whiteflags; 06-06-2006 at 10:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rectangle class
    By blackant in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2009, 08:33 AM
  2. segmetation fault (reading and writing file in c)
    By tasosa in forum C Programming
    Replies: 5
    Last Post: 04-13-2009, 06:04 AM
  3. GUI structure in C
    By officedog in forum C Programming
    Replies: 36
    Last Post: 11-19-2008, 02:33 PM
  4. Point passed rectangle...
    By Hunter2 in forum Game Programming
    Replies: 15
    Last Post: 10-10-2003, 09:57 AM
  5. Collision detection algorithm
    By Hannwaas in forum Game Programming
    Replies: 5
    Last Post: 11-30-2001, 01:27 PM