C++ 没有用于调用的匹配函数
在我的对象“处理程序”中 我有以下代码:C++ 没有用于调用的匹配函数,c++,sockets,C++,Sockets,在我的对象“处理程序”中 我有以下代码: Product tempProduct; // temporary Product storage variable LINE481 tempProduct.setHandler(this); 在我的产品中。h: #include <string> #include <qtimer.h> #include "HandleTCPClient.h" #ifndef PRODUCT_H #define PRODUCT_H
Product tempProduct; // temporary Product storage variable
LINE481 tempProduct.setHandler(this);
在我的产品中。h:
#include <string>
#include <qtimer.h>
#include "HandleTCPClient.h"
#ifndef PRODUCT_H
#define PRODUCT_H
class Handler;
//Define ourselves a product class
class Product
{
void startTimer();
public:
Product();
string seller, itemName, description, highestBidder;
double price, min, buyingPrice, currentBid;
int time;
bool isSold;
Handler handler();
void setHandler(Handler h);
public slots:
void setProductToSold();
};
#endif
this
的类型是指向Handler类的对象的指针,但是您的setHandler
应该是Handler
对象。因此存在类型不匹配。更改setHandler的签名以接受处理程序*,使其工作。您不会显示Handler::HandleTCPClient(int,std::string,std::string)
,但其中可能有类似的内容
setHandler (&somehandler);
而不是
setHandler (somehandler);
您可能希望像下面这样声明
setHandler
函数:
void Product::setHandler(Handler *h)
Handler *handler;
另外,在Product类中,声明处理程序,如下所示:
void Product::setHandler(Handler *h)
Handler *handler;
看起来您可能更熟悉没有显式指针语法的语言,如Java或Python。在C++中,必须使用<代码> */Cuth>指示显式声明指针,否则编译器将尝试复制和传递值对象(通过复制构造函数复制整个对象)。 < P>添加const:
void setHandler(const Handler & h);
及
并致电:
tempProduct.setHandler(this->handler());
我不明白你怎么用这个接线员???打电话
tempProduct.setHandler(*this) 非常感谢,是的,我更熟悉Java>。
tempProduct.setHandler(this->handler());