How to use a class object in C++ as a function parameter

后端 未结 5 1938
离开以前
离开以前 2021-01-30 07:15

I am not sure how to have a function that receives a class object as a parameter. Any help? Here is an example below.

#include

void function(cla         


        
5条回答
  •  自闭症患者
    2021-01-30 07:39

    I was asking the same too. Another solution is you could overload your method:

    void remove_id(EmployeeClass);
    void remove_id(ProductClass);
    void remove_id(DepartmentClass);
    

    in the call the argument will fit accordingly the object you pass. but then you will have to repeat yourself

    void remove_id(EmployeeClass _obj) {
        int saveId = _obj->id;
        ...
    };
    
    void remove_id(ProductClass _obj) {
        int saveId = _obj->id;
        ...
    };
    
    void remove_id(DepartmentClass _obj) {
        int saveId = _obj->id;
        ...
    };
    

提交回复
热议问题