질문 : 나는 주된 기능에 사용 된 클래스를 삭제했으며 정의되지 않은 오류가 발생합니다. 그런 다음 .h 파일을 추가하고 다른 오류가 발생합니다. 제 질문은 .cpp 클래스 파일에 따라 .h를 작성하려고합니다. 여기에 세부 사항은 다음과 같습니다C++ 헤더 파일 및 클래스 정의 문제
내가 ElevatorButton.cpp에 declated이 클래스가 있습니다
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class ElevatorButton
{
public:
int pressed = 0; // boolean
void myFunc(int param1)
{
cout << param1 << endl;
}
};
을 그리고 내가 ElevatorSimulation.cpp이 파일이 : 코드가 정기적으로 오류가 발생 컴파일
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Header.h"
using namespace std;
int main()
{
ElevatorButton ElvBtn;
cout << ElvBtn.myFunc(1) << endl;
}
합니다. 헤더 파일을 선언해야합니다. 그러나 내 헤더 파일에서 정의를 어떻게 관리해야합니까? 나는 .h 파일에 대해 읽었지만 여전히 혼란 스럽다. 여기 내 header.cpp입니다 :
#ifndef ElevatorButton_H
#define ElevatorButton_H
class ElevatorButton
{
public:
int pressed = 0; // boolean
public:
void myFunc(int param1){};
};
#endif
하지만 그것은 header.h가 다음과 같은 오류가 발생합니다 :
1>ElevatorSimulation.cpp(14): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
때로는 단순히 오류 메시지 (그것을 포함하기위한 명성)를 읽는 것만으로 충분합니다. ... 그렇지 않은 것보다 더 옳지 않습니다. – Deduplicator
'header.cpp'는 꽤 잘못 들립니다 : P ... –