Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place an object in a struct

Normal way to make a new object:

std::string date1 = "10/1/2010"; Date d1(stringToChar(date1);

But I can't figure out how to use that in a struct. The struct:

struct RecPayments
{
    std::string name;
    Date datemake();
    float cost;
};

Trying to use it like this:

void addRecurring()
{
    //New recurring payment
    RecPayments * newPaymentItem = new RecPayments;

    //Set recurring payment properties
    newPaymentItem->name = "Test Payment";
    newPaymentItem->datemake(stringToChar("4/12/2011"));
    newPaymentItem->cost = 5;
}

Error received:

error: no matching function for call to ‘RecPayments::datemake(const char*)

What's the proper way to do this?

like image 615
natli Avatar asked Dec 04 '11 17:12

natli


1 Answers

Well, the compiler is right. The way you've used the struct has given you (in effect) a class. You declared a function RecPayments::datemake() but never defined it anywhere. What's more, you didn't even call this version of the function you created--you sent with it an argument that it didn't expect.

You need to remove the () in the datemake variable you've declared, or make a full function out of it. I'm not sure from the question which one you wanted.

like image 112
semisight Avatar answered Oct 13 '22 00:10

semisight