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

来源:互联网 发布:广告软件有哪些 编辑:程序博客网 时间:2024/04/30 14:42
#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;
}