Reputation: 1497
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:
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
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)
Upvotes: 1
Views: 5609
Reputation: 3519
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 ???
Upvotes: 0
Reputation: 992747
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).
Upvotes: 2
Reputation: 57774
You don't show Handler::HandleTCPClient(int, std::string, std::string)
, but presumably within it is something like
setHandler (&somehandler);
instead of
setHandler (somehandler);
Upvotes: 0
Reputation: 73433
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.
Upvotes: 0