main() 및 여러 호스트 클래스의 멤버 함수에서 사용할 수있는 수학 함수를 만들었습니다. 범위에서이 수학 함수를 전역으로 만드는 것이 가장 쉽다고 생각했지만 어떻게해야할지 모르겠습니다.전역 함수 선언 및 문제 해결 문제가 발생했습니다.
저는 현재 모든 기능을 Rdraws.cpp라는 파일에 Rdraws.h의 프로토 타입과 함께 넣었습니다. #includes
과 externs
이 있더라도 main()의 첫 번째 함수 호출에서 "기호를 찾을 수 없음"컴파일러 오류가 발생합니다.
여기에 내가 가진 무엇 :
// Rdraws.cpp
#include <cstdlib>
using namespace std;
#include <cmath>
#include "Rdraws.h"
#include "rng.h"
extern RNG rgen // this is the PRNG used in the simulation; global scope
void rmultinom(double p_trans[], int numTrials, int numTrans, int numEachTrans[])
{ // function 1 def
}
void rmultinom(const double p_trans[], const int numTrials, int numTrans, int numEachTrans[])
{ // function 2 def
}
int rbinom(int nTrials, double pLeaving)
{ // function 3 def
}
// Rdraws.h
#ifndef RDRAWS
#define RDRAWS
void rmultinom(double[], int, int, int[]);
void rmultinom(const double[], const int, int, int[]);
int rbinom(int, double);
#endif
// main.cpp
...
#include "Rdraws.h"
...
extern void rmultinom(double p_trans[], int numTrials, int numTrans, int numEachTrans[]);
extern void rmultinom(const double p_trans[], const int numTrials, int numTrans, int numEachTrans[]);
extern int rbinom(int n, double p);
RNG rgen; // global PRNG object created for simulation
int main() { ... }
내가 프로그래밍에 아주 새로운 해요. 이렇게하는 것이 현명하게 똑똑한 방법이라면, 나는 알고 싶습니다.
업데이트
나는 바보 그리고 난 여전히 내 컴파일러에 Rdraws.cpp을 포함하지 않았 몰랐어요. 포스터에서 언급했듯이 세미콜론도 잊어 버렸습니다.
여기에 설명 된 방법을 개선 할 수 있다면 나에게도 감사드립니다.
Meh. 누군가 "꽤 프로그래밍에 익숙하지 않은"사람에게는 꽤 좋아 보인다. –