I am new to C++ and just learned about classes in a course I watched, I'm trying to make a little blockchain project and I'm having trouble with constructors. I have a class, Transaction
whose constructor takes in three parameters, and am trying to make that a parameter of another class, Block
's constructor. Here is the definition for the constructor of Transaction
,
Transaction::Transaction(std::string fromAddress, std::string toAddress, uint32_t amount)
{
this->fromAddress = fromAddress;
this->toAddress = toAddress;
this->amount = amount;
}
And I'm trying to use the Transaction
class as a parameter for the Block
class
Block::Block(time_t timestamp, Transaction transaction(std::string fromAddress, std::string
toAddress, uint32_t amount), std::string prevHash)
{
this->timestamp = time(nullptr);
this->transactionSet(std::string fromAddress, std::string toAddress, uint32_t amount) =
transaction(std::string fromAddress, std::string toAddress, uint32_t amount);
this->prevHash = "";
}
But I get tons of errors for doing this, I tried a ton of different ways but I don't know how to implement it, so how do you use a parameterized object as a parameter for another class?