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)
{
}


相关文章
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
555 0
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Error: Element type is invalid: expected a string (for built-in components) or a class/function
2550 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
VS2005 error C2864 only static const integral data members can be initialized within a class
VS2005 error C2864 only static const integral data members can be initialized within a class
|
Java 关系型数据库 MySQL
15. 成功解决:java: Can't generate mapping method with primitive return type.
今天启动 SpringBoot 项目时,报了如下错误:`java: Can't generate mapping method with primitive return type.`
1016 0
|
Java
JAVA解决方案:Missing URI template variable ‘customersno‘ for method parameter of type String
解决方案 PathVariable和RequestParam的使用 @PathVariable @RequestParam PathVariable和RequestParam的区别 区别在于一个是用?,一个使用/进行传输数据
348 0
No package ‘libmarco-private‘ found
No package ‘libmarco-private‘ found
56 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)]