こんにちは私はComputer.cppのsetメソッドを取得しています。私は型キャストエラーを得ることに保つようにC++型のキャストエラーの設定と、配列からの派生クラスメンバの取得(**)
表現 から参照型「constのケース&」の無効な初期化などのタイプ「ケース」または「パート」、「パート*」の
として私は何をしたいここで配列
Part** m_requiredParts;
に(「パート」とは、などの場合、モニター、CPUなどの各種のコンクリート部品のスーパークラスである)別のコンピュータ部品を格納することです私は、コードのエキスですそれをqt creで実行するator 3.6.0。
Computer.h
#ifndef COMPUTER_H
#define COMPUTER_H
class Computer : public ComputerPlan
{
public:
/**
* @brief Computer default constructor
*/
Computer();
/**
* @brief ~Computer destructor
*/
virtual ~Computer();
// Getters
/**
* @brief getCase retrieves the computer's case information
* @return the computer's Case
*/
virtual const Case& getCase() const;
// Setters
/**
* @brief setCase setter method for Case
* @param computerCase computer's Case
*/
virtual void setCase(const Case &computerCase);
protected:
Part** m_requiredParts;
};
#endif // COMPUTER_H
.CPPは、いくつかのaddtionalの情報を追加する
Computer.cpp
#include "Computer.h"
Computer::Computer()
{
m_requiredParts = new Part* [8];
}
Computer::~Computer()
{
}
const Case& Computer::getCase() const
{
const Case& c = (Case&)m_requiredParts[0];
return c;
}
void Computer::setCase(const Case &computerCase)
{
m_requiredParts[0] = (Part*) &computerCase;
//Part**
}
ファイルヘッダファイル
、
私は設定してmain.cppに、以下の方法でそれらを取得しています
Computer* computer = new Computer();
computer->setCase(Case("NZXT", Tower));
std::string expected = "Case: NZXT, Case Type: Tower";
std::string actual = std::string(computer->getCase().getPartInformation());
delete computer;
return expected == actual;
をoutlivesために起こっている?を確認する必要があり
– NathanOliver