Header file help

This is a discussion on Header file help within the C++ Programming forums, part of the General Programming Boards category; Having trouble getting my header file to compile correctly. Code: #ifndef Rectangle_h #define Rectangle_h class Rectangle { public: double avgPerimeter; ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    11

    Header file help

    Having trouble getting my header file to compile correctly.
    Code:
    #ifndef Rectangle_h
    #define Rectangle_h
    class Rectangle
    {              
                            
          public:
                 double avgPerimeter;
                 double avgArea,count; //count used a a counter to keep track of number of times i've computed the perimeter and area.
                 double x,y,h,w;
                 double Area, Perimeter;
                 Rectangle();
                 double getPerimeter();           
                 double getArea();                   
                 friend ostream& operator<<(ostream& outputStream, Rectangle& z);
                 friend istream& operator>>(istream& inputStream, Rectangle& z); 
                 
           private: 
                 char color[]; 
    };
    #endif
    Getting a compile error of
    ISO C++ forbids declaration of 'ostream' with no type
    'ostream' is neither function nor member function; cannot be declared friend
    expected ';' before '&' token
    It is also saying the same thing with the istream. I'm not sure where to go from here, this code was working till I broke off the code to a header file. Well it was working when all of my code was in the same file.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    after your #define do:
    #include<iostream>
    using namespace std;

    also you cant declare an array without giving the size, so you have to make color a pointer instead

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    11
    Thanks, it fixed it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM

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