Passing object in c++ in a constructor

Правка en1, от Sumanto, 2020-09-10 08:03:27

My earlier code which was giving error: complete implementation here: https://ideone.com/MuOmlS

class Meeting
{
private:
    int start, end;
    Room room;

public:
    Meeting(int _start, int _end, Room _room)
    {
        start = _start;
        end = _end;
        room = _room;
    }
};
    //constructor was called
    // as calendar.push_back(Meeting(_start, _end, this));

.
.
.

This Code giving error as:


[ERROR]: error: field ‘room’ has incomplete type ‘Room’ Room room; ^~~~ a.cpp: In constructor ‘Meeting::Meeting(int, int, Room)’: a.cpp:23:40: error: ‘_room’ has incomplete type Meeting(int _start, int _end, Room _room) ^~~~~ a.cpp: In member function ‘bool Room::book(int, int)’: a.cpp:72:54: error: no matching function for call to ‘Meeting::Meeting(int&, int&, Room*)’ calendar.push_back(Meeting(_start, _end, this)); ^

correct code after referring this thread https://stackoverflow.com/questions/12466055/field-has-incomplete-type-error/12466219 i implemented and it worked but from this thread i couldn't able to understand why pointer object is doing which leads to removal of error? complete implementation here: https://ideone.com/SSVnOU

class Meeting
{
private:
    int start, end;
    Room *room;

public:
    Meeting(int _start, int _end, Room *_room)
    {
        start = _start;
        end = _end;
        room = _room;
    }
    //constructor was called
    // as Meeting(new_start,new_end,this);
..

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский Sumanto 2020-09-10 08:53:08 21
en2 Английский Sumanto 2020-09-10 08:46:08 704
en1 Английский Sumanto 2020-09-10 08:03:27 1719 Initial revision (published)