没有合适的默认构造函数可用

#include  " stdafx.h "
#include
< iostream >
using   namespace  std;

class  A {
public:
    
static void OutOK(){
        cout
<<"A ok"<<endl;
    }

}
;

class  B {
public:
    B()
{
        cout
<<"construct B"<<endl;
    }

    B(
int i){
        cout
<<"construct B with int"<<endl;
    }

    
static void OutOK(){
        cout
<<"B ok"<<endl;
    }

}
;

class  C {
public:
    C(
int i){
        cout
<<"construct C with int"<<endl;
    }

    
static void OutOK(){
        cout
<<"C ok"<<endl;
    }

}
;

int  main() {
    A a;
    a.OutOK();

    B b;
    b.OutOK();
    B bint(
2);
    bint.OutOK();

    C c; 
// error C2512: “C”: 没有合适的默认构造函数可用
    c.OutOK();

    
return 0;
}
 

你可能感兴趣的:(C/C++)