Results 1 to 2 of 2

Thread: [RESOLVED] Overloading default constructor

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved [RESOLVED] Overloading default constructor

    Hello,

    HTML Code:
    g++ (GCC) 4.6.0
    I have a class I want to create constructors for. However, as I have structure as part of the class I am running into difficultly since I overloaded the constructor.

    I have my default constructor with a initializer list and I have a default constructor for the structure in the class.

    However, when I added my overloaded constructor I keep getting the following errors, not sure why:

    Code:
    error: Floor_plan::Floor_plan()’ cannot be overloaded
    error: with ‘Floor_plan::Floor_plan()’
    Code:
    class Floor_plan
    {
    private:
        unsigned int width;
        unsigned int height;
    
        struct floor_size {
            unsigned int x;
            unsigned int y;
    
            // Constructor
            floor_size() {}
            floor_size(unsigned int _x, unsigned int _y) : x(_x), y(_y) {}
        } floor;
    
    public:
        Floor_plan() {}
        Floor_plan() : width(1), height(2), floor(10, 20) {}
        Floor_plan(unsigned int _width, unsigned int _height, unsigned int _x, unsigned int _y);
        ~Floor_plan() {};
    
        unsigned int get_floor_width();
        unsigned int get_floor_height();
        unsigned int get_floor_x_coordinate();
        unsigned int get_floor_y_coordinate();
        void set_floor_width(unsigned int _width);
        void set_floor_height(unsigned int height);
    
        void print_floorplan();
    };
    Many thanks for any suggestions,
    steve

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Overloading default constructor

    You have two parameterless constructors defined.
    The fact that one has an initializer list is irrelevant.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width