cannot convert parameter 1 from 'class A' to 'class A'

简介: cannot convert parameter 1 from 'class A' to 'class A'

出错代码:

class A
{
public:
         A(){};
private:
         CStringArray x ;
};
fun(A a)
{
}
void CTest22Dlg::OnButton1()
{
         A a;
         fun(a);
}

运行结果:

error C2664: 'fun' : cannot convert parameter 1 from 'class A' to 'class A'

原因分析:

 没有拷贝构造函数。

解决思路:

1)增加拷贝构造函数。

2)更改fun函数的参数为引用型。

解决办法:

1)更改类定义。

class A
{
public:
         A(){};
         A(const A& other){/*...*/};
private:
         CStringArray x ;
};

2)更改函数定义。

fun(const A& a)
{
}


相关文章
|
12月前
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
345 0
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
error : Class declarations lacks Q_OBJECT macro
error : Class declarations lacks Q_OBJECT macro
|
11月前
|
JSON 数据格式
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
3458 0
|
Java 关系型数据库 MySQL
15. 成功解决:java: Can't generate mapping method with primitive return type.
今天启动 SpringBoot 项目时,报了如下错误:`java: Can't generate mapping method with primitive return type.`
643 0
|
Java
JAVA解决方案:Missing URI template variable ‘customersno‘ for method parameter of type String
解决方案 PathVariable和RequestParam的使用 @PathVariable @RequestParam PathVariable和RequestParam的区别 区别在于一个是用?,一个使用/进行传输数据
275 0
No package ‘libmarco-private‘ found
No package ‘libmarco-private‘ found
42 0
IllegalArgumentException Parameter value [4] did not match expected type [java.lang.String (na)]
IllegalArgumentException Parameter value [4] did not match expected type [java.lang.String (na)]