명시 적 수퍼 클래스 생성자를 호출하는 상속 된 클래스에서 매우 실망 스럽습니다. 구문을 올바르게 이해하지 못하는 것 같습니다!헤더 파일을 사용하는 동안 C++ 명시 적 수퍼 클래스 생성자 문제
지금까지 본 모든 예제는 헤더 파일을 사용하여 forward-declarations에서 헤더 및 인라인 클래스 정의 ({} 사용)를 구분하지 않으므로 잘 모르겠습니다. .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
}
미리 감사드립니다.
감사! 나는 Jeff를 13 초 이겼을 것입니다. 그래서 당신의 대답을 받아 들일 것입니다. (미안 제프!) –
고마워! 몇 가지 이유로 C++ 자습서의 대부분은 분리 된 h 및 cc 파일을 사용할 때 상황이 어떻게 나타나지 않는지를 보여줍니다. – jotadepicas