c++没有来自“myClass1”的合适的用户定义转换到“myClass1”存在
我对 C++ 非常陌生,当 Visual Studio 2010 突出显示此语法错误时,我感到非常困惑。 定义
class myClass1 {
public:
myClass1();
}
class myClass2 {
public:
myClass2();
void doSomething(myClass1 thing) {};
}
int main(int argc, char* argv[]) {
vector<myClass1> arr;
arr.resize(1);
arr[0] = myClass1();
myClass2 c2 = myClass2();
c2.doSomething(arr[0]); //this line is being highlighted as giving the error in the title
};
我真的很困惑这意味着什么。
语法错误位于我评论的行,它给出了错误“没有合适的用户定义的从“myClass1”到“myClass1”的转换。
编辑:抱歉没有明确问题
I'm very new to c++ and was really confused when this syntax error was highlighted by visual studio 2010.
Definitions
class myClass1 {
public:
myClass1();
}
class myClass2 {
public:
myClass2();
void doSomething(myClass1 thing) {};
}
int main(int argc, char* argv[]) {
vector<myClass1> arr;
arr.resize(1);
arr[0] = myClass1();
myClass2 c2 = myClass2();
c2.doSomething(arr[0]); //this line is being highlighted as giving the error in the title
};
I'm just really confused as to what this means.
The syntax error is at the line that i commented and it gives the error "no suitable user-defined conversion from "myClass1" to "myClass1".
Edit: sorry about not making the question clear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
myClass* 类不包含任何内容/不执行任何操作,因此很难理解您的目的。
您的代码将无法编译,因为未定义构造函数。
您应该始终在代码粘贴中提供最少的相关信息(而不是更多)。
要在堆栈上声明 myClass2 对象的实例,只需执行以下操作:
doSomething
方法使用 myClass1 的副本,这可能不是您想要的。未定义复制构造函数(但没有任何内容可复制)。
另外该函数什么也不做...
The myClass* classes contain nothing/do nothing so it's kind of hard to understand your purpose.
Your code won't compile because the constructors are not defined.
You should always provide a minimum of relevant information (and not much more) in your code pastes.
To declare an instance of a myClass2 object on the stack, simply do:
The
doSomething
method uses a copy of myClass1, which is probably not what you want.The copy constructor is not defined (but there is nothing to copy).
Plus the function does nothing...