C++: how to choose the constructor depending on the condition?

后端 未结 5 1459
长发绾君心
长发绾君心 2021-01-24 19:30

Assume I have a class with different constructors:

class A
{
public:
    A(char* string)
    {
        //...
    }

    A(int value)
    {
        //..
    }

           


        
5条回答
  •  轮回少年
    2021-01-24 20:04

    You can use the template class:

    template class A
    {
    protected:
        type    T;
    public:
    
        void A(type t_curr) {T = t_curr;};//e.g.---
    
        void check() {}
    };
    

提交回复
热议问题