Thread: Function redefinition

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    117

    Function redefinition

    When I build my project, I get these errors -
    Code:
    /home/sterling/CODE/Dormitory/Hallway.h|51|error: redefinition of ‘int& Hallway::getAvaL()’|
    /home/sterling/CODE/Dormitory/Hallway.h|42|error: ‘int& Hallway::getAvaL()’ previously defined here|
    /home/sterling/CODE/Dormitory/Hallway.h|56|error: redefinition of ‘int& Hallway::getAvaW()’|/home/sterling/CODE/Dormitory/Hallway.h|43|error: ‘int& Hallway::getAvaW()’ previously defined here|
    I don't understand how the functions are being redefined. My .h and .cpp are -

    Code:
    #ifndef HALLWAY_H
    #define HALLWAY_H
    #include "Bathroom.h"
    #include "Bedroom.h"
    class Hallway {
    
    public:
    
        Hallway();
        ~Hallway();
    
        const int& getLength();
        const int& getWidth();
    
        void setAvaL(int&);
        int& getAvaL();
        void setAvaW(int&);
        int& getAvaW();
        std::vector<Bathroom>& getBathrooms();
        std::vector<Bedroom>& getBedrooms();
    
        void addBedroom(Bedroom&);
        void addBathroom(Bathroom&);
    
    private:
        std::vector<Bedroom> bedrooms;
        std::vector<Bathroom> bathrooms;
        const int length;
        const int width;
        int avaL;
        int avaW;
    };
    #endif
    Code:
    #include "Hallway.h"
    
    Hallway::Hallway()
    : length(300), width(100) {}
    
    Hallway::~Hallway() {}
    
    const int& Hallway::getLength() {return length;}
    const int& Hallway::getWidth() {return width;}
    
    int& Hallway::getAvaL() {return avaL;}
    int& Hallway::getAvaW() {return avaW;}
    
    std::vector<Bathroom>& Hallway::getBathrooms() {return bathrooms;}
    std::vector<Bedroom>& Hallway::getBedrooms() {return bedrooms;}
    
    void Hallway::setAvaL(int& l) {
        avaL = l;
    }
    int& Hallway::getAvaL() {return avaL;}
    
    void Hallway::setAvaW(int& w) {
        avaW = w;
    }
    int& Hallway::getAvaW() {return avaW;}
    Not sure what else to say about it other than I just don't get at all how they are being redefined...can anyone help me out? I have other classes in the project which I can share if they are needed. But they all compile fine.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include "Hallway.h"
    
    Hallway::Hallway()
    : length(300), width(100) {}
    
    Hallway::~Hallway() {}
    
    const int& Hallway::getLength() {return length;}
    const int& Hallway::getWidth() {return width;}
    
    int& Hallway::getAvaL() {return avaL;}
    int& Hallway::getAvaW() {return avaW;}
    
    std::vector<Bathroom>& Hallway::getBathrooms() {return bathrooms;}
    std::vector<Bedroom>& Hallway::getBedrooms() {return bedrooms;}
    
    void Hallway::setAvaL(int& l) {
        avaL = l;
    }
    int& Hallway::getAvaL() {return avaL;}
    
    void Hallway::setAvaW(int& w) {
        avaW = w;
    }
    int& Hallway::getAvaW() {return avaW;}
    You've got that in there twice.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    117

    s

    OOH wow okay thanks, solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive function
    By WatchTower in forum C Programming
    Replies: 11
    Last Post: 07-15-2009, 07:42 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM