question on class rectangle.h

This is a discussion on question on class rectangle.h within the C++ Programming forums, part of the General Programming Boards category; hellow everyone have a question hope u can help, im writing a program that has a class rectangle.h and include ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    14

    Unhappy question on class rectangle.h

    hellow everyone have a question hope u can help, im writing a program that has a class rectangle.h and include member functions in a file called ectangle.cpp. The problem is that aim getting an error message "can not open file rectangle .h" i don't understand why? here is part of the program
    [code]
    #ifndef RECTANGLE_H
    #define RECTANGLE_H

    class rectangle{
    public:
    rectangle(int lenght = 1,int width = 1);
    void setRectangle( int,int);
    void setLenght(int);
    void setWidth(int);

    int getRectangle();
    int getLenght();
    int getWidth();

    void printArea();
    void printPerimeter();

    private:
    int rec;
    int lenght;
    int width;

    };
    #endif

    #include <iostream>
    using std::cout;
    #include <iomanip>
    using std::setfill;
    using std::setw;

    #include "rectangle.h"
    [\code]

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    The first part of the program up to and including the #endif should be in a separate file in your project's directory called "rectangle.h"

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    14
    so thats what im doing wrong! im putting it all in the same program. ok im using 6.0 compiler do i use a header file for the .h and a source file for the cpp? im not sure.

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Yeah, though it doesn't really matter what you choose when you click create new file -- both headers and source files are just ascii files. Just make sure that you put the proper extension. Choosing header will automatically append .h and choosing source will automatically append .cpp

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    14
    i still don't know how to do it, i know what you mean that they have to be in different files but how do i do that?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    file 1, aka myfile.h
    Code:
    #ifndef MYHEADER
    #define MYHEADER
    
    ...stuff goes here...
    
    #endif
    file 2, aka myfile.cpp
    Code:
    #include<somestuffhere>
    #include "myheader.h"
    
    int main ( )
    {
        ....code goes here...
        return 0;
    }
    
    ...maybe more code goes here...
    Something like that.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Dec 2002
    Posts
    14
    thanks a lot! to u both i fixed it now it works thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  2. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 05:08 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21