对巨硬的c++编译器懂得不能!求帮助
对巨硬的c++编译器理解不能!求帮助。
这样无法编译通过,提示没有指定默认构造函数。
删除那个拷贝构造函数,可以编译通过,如下
我的问题是:c++标准这样规定,如果你没有显示实现无参构造函数,编译器会为你实现。
可以看到我下面的代码是符合这个规定的,编译器也为我构造了无参的默认构造函数,可以编译通过。
但是上面那段代码,只是因为我多实现了一个拷贝构造函数,编译器就不再为我实现无参默认构造函数?
这是什么道理?请问是不是巨硬的编译器反人类?还是精神分裂?
------解决方案--------------------
A default constructor for a class X is a constructor of class X that can be called without an argument. If there is no user-declared constructor for class X, a default constructor is implicitly declared.
------解决方案--------------------
maybe 一旦你声明了任何形式的构造函数,那么编译器就不管了
------解决方案--------------------
我加了头文件
这样无法编译通过,提示没有指定默认构造函数。
class static_class{
static void fun(){}
protected:
static_class(static_class& rhs)
{
a = rhs.a;
}
private:
int a;
};
void main() {
static_class c;
getchar();
}
删除那个拷贝构造函数,可以编译通过,如下
class static_class{
static void fun(){}
private:
int a;
};
void main() {
static_class c;
getchar();
}
我的问题是:c++标准这样规定,如果你没有显示实现无参构造函数,编译器会为你实现。
可以看到我下面的代码是符合这个规定的,编译器也为我构造了无参的默认构造函数,可以编译通过。
但是上面那段代码,只是因为我多实现了一个拷贝构造函数,编译器就不再为我实现无参默认构造函数?
这是什么道理?请问是不是巨硬的编译器反人类?还是精神分裂?
------解决方案--------------------
A default constructor for a class X is a constructor of class X that can be called without an argument. If there is no user-declared constructor for class X, a default constructor is implicitly declared.
------解决方案--------------------
maybe 一旦你声明了任何形式的构造函数,那么编译器就不管了
------解决方案--------------------
我加了头文件