明示的なスーパークラスコンストラクタを呼び出す継承されたクラスで、非常に不満を感じているようです。私は構文の権利を得ることができません!C++明示的スーパークラスコンストラクタヘッダーファイルの使用中に問題が発生する
これまで見たすべての例では、ヘッダーファイルを使って前方宣言からヘッダーとインラインクラス定義({} 'を使用)を分けることはありません。 .hと.ccファイルの間の構文をどのようにカバーするか。どんな助けもありがとう!ここで
は、コンパイラが私を与えるエラー(GCC)です:serverconnection.h: In constructor "ServerConnection::ServerConnection(std::string, std::string)": serverconnection.h:25: error: expected `{' at end of input serverconnection.cc: At global scope: serverconnection.cc:20: error: redefinition of "ServerConnection::ServerConnection(std::string, unsigned int, short unsigned int, PacketSender*, int)" serverconnection.h:25: error: "ServerConnection::ServerConnection(std::string, unsigned int, short unsigned int, PacketSender*, int)" previously defined here serverconnection.cc: In constructor "ServerConnection::ServerConnection(std::string, std::string)": serverconnection.cc:20: error: no matching function for call to "Connection::Connection()"
私は接続(デフォルト接続のコンストラクタを呼び出すようにしようとしていることを理解し)、それはちょうど私の構文を理解していないよう。
ここコードである:
connection.h:
class Connection {
public:
Connection(string myOwnArg);
};
connection.cc:
#include "connection.h"
Connection::Connection(string myOwnArg) {
//do my constructor stuff
}
serverconnection.h:
#include "connection.h"
class ServerConnection : public Connection {
public:
ServerConnection(string myOwnArg, string superClassArg) : Connection(superClassArg);
};
serverconnection.ccは:
#include "serverconnection.h"
#include "connection.h"
ServerConnection::ServerConnection(string myOwnArg, string superClassArg) {
//do my constructor stuff
}
ありがとうございます!
ありがとうございます!私はあなたがジェフを13秒遅らせると思うので、私はあなたの答えを受け入れられたとマークします(申し訳ありませんジェフ!) –
ありがとう!何らかの理由で、大部分のC++チュートリアルでは、別々のhおよびccファイルを使用しているときの状態を表示していません。 – jotadepicas