How can I detect whether a type is a visible base of another type?

后端 未结 3 1307
夕颜
夕颜 2021-02-19 17:29

If I do

struct A{};
struct C:private A{};

typedef char (&yes)[1];
typedef char (&no)[2];

template 
struct Host
{
 operato         


        
3条回答
  •  春和景丽
    2021-02-19 18:00

    Do you need something that can be evaluated at runtime, or will a simple compile time error suffice?

    struct A {};
    struct B : private A {};
    
    int main()
    {
       B b;
    
       // gives error C2243: 'static_cast' : conversion from 'B *' to 'A &' exists, but is inaccessible
       A& a = static_cast(b);
    
       return 0;
    }
    

提交回复
热议问题