我是 C++ 新手,刚刚在我看过的课程中学习了类,我正在尝试制作一个小区块链项目,但在构造函数方面遇到了麻烦。我有一个类,Transaction
它的构造函数接受三个参数,并试图使它成为另一个类Block
的构造函数的参数。这是构造函数的定义Transaction
,
Transaction::Transaction(std::string fromAddress, std::string toAddress, uint32_t amount)
{
this->fromAddress = fromAddress;
this->toAddress = toAddress;
this->amount = amount;
}
我正在尝试使用Transaction
该类作为该类的Block
参数
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 = "";
}
但是这样做会遇到很多错误,我尝试了很多不同的方法,但我不知道如何实现它,那么如何使用参数化对象作为另一个类的参数呢?