开发者

c++ no suitable user-defined conversion from "myClass1" to "myClass1" exists

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


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:

myClass2 c2;

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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜