开发者

No Matching Function for Call to

In my object ' handler ' I have the following code:

Product tempProduct; // temporary Product storage variable
LINE481    tempProduct.setHandler(this);

Within my Product.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:
        Pro开发者_如何学Goduct();

        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

For my Product.cpp:

#include <string>
using std::string;

#include "Product.h"

Product::Product()
{
    seller = "";
    itemName = "";
    price = 0.00;
    min = 0.00;
    buyingPrice = 0.00;
    time = 0;
    description = "";
    highestBidder = "None";
    currentBid = 0.00;
}

void Product::setHandler(Handler h)
{
    handler = h;
}

The issue I am having:

HandleTCPClient.cpp: In member function âint Handler::HandleTCPClient(int, std::string, std::string)â:
HandleTCPClient.cpp:481: error: no matching function for call to âProduct::setHandler(Handler* const)â
Product.h:34: note: candidates are: void Product::setHandler(Handler)


You probably want to declare your setHandler function like this:

void Product::setHandler(Handler *h)

Also, inside the Product class, declare handler like this:

Handler *handler;

It looks like you might be more familiar with a language such as Java or Python that doesn't have an explicit pointer syntax. In C++, you must explicitly declare pointers using the * indication, otherwise the compiler will try to copy and pass around value objects (copying the whole object through its copy constructor).


The type of this is a pointer to object of Handler class, but your setHandler is expecting Handler object. So there is a type mismatch. Change the signature of setHandler to accept a Handler* to make it work.


You don't show Handler::HandleTCPClient(int, std::string, std::string), but presumably within it is something like

setHandler (&somehandler);

instead of

setHandler (somehandler);


Add const:

void setHandler(const Handler & h);

and

void Product::setHandler(const Handler  & h)
{
    handler = h;
}

and call:

tempProduct.setHandler(this->handler());

I dont understand wh you use this operator ???


call

tempProduct.setHandler(*this);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜