이것은 완벽하게 컴파일됩니다.ld가 매개 변수를 전달할 때 종료 상태 오류 1을 반환했습니다.
const int NUM_PLAYERS = 10;
struct wrType
{
string name[NUM_PLAYERS];
string team[NUM_PLAYERS];
int catches[NUM_PLAYERS];
int yards[NUM_PLAYERS];
int td[NUM_PLAYERS];
double ypc[NUM_PLAYERS];
};
void populateList(wrType[], ifstream&);
int main(int args, char* argv[])
{
wrType *wide;
char select;
ifstream in;
in.open(argv[1]);
/*populateList(wrType wide, ifstream in); code causing error*/
}
void populateList(wrType wide, ifstream in)
{
};
나는 다음과 같은 코드를
'populateList(wide, in);'
주석을 제거하자마자 내가 컴파일 한 후 다음과 같은 오류를
'ld returned 1 exit status error'
를 얻을. 많은 포럼을 살펴본 결과 문제를 해결할 수 없었습니다. 우리는 최근에 구조체와 수업을 들었습니다. 개념을 오해하는지, 어떻게 작동 시킬지 잘 모르겠습니다.
코드는 명령 줄을 통해 파일을 전달한 다음 나중에 액세스하여 10 명의 선수 인 축구 선수의 다른 통계를 기준으로 정렬 할 수 있습니다. 나는 내 손을 잡고 싶지 않아서 나중에 내가 고난을 겪고 나머지를 나에게 맡겼다. 이 코드는 함수없이 main 내에서 작동하지만 내가 가진 코드로 함수를 호출하자마자 오류가 발생합니다.
'In function
main': (.text+0xad): undefined reference to
populateList(wrType*, std::basic_ifstream >&)' collect2: error: ld returned 1 exit status'
편집 2 : 나는 그것이 나에게로 변환 할 수 없습니다 MYTYPE을 제공 포인터로를 통과 할 때
또한 * 전체 오류와
업데이트를 MYTYPE하는 코드와를
:
'populateList(wrType wide, ifstream in);'
다음과 같은 오류를 반환 'int main (int, char **)'함수에서 :
34:22: error: expected primary-expression before ‘wide’ populateList(wrType wide, ifstream in); ^ 34:37: error: expected primary-expression before ‘in’ populateList(wrType wide, ifstream in);
1.이 오류 메시지가 표시됩니까? 2. 주석 처리되지 않은 코드는 무엇을해야합니까? 3. Visual C++을 사용하고 있습니까? –
주석 처리 된 코드가 populateList 함수를 호출하려고합니까? 이 경우에'populateList (wide, in);를 원한다. 당신의 함수는 당신이 그것을 호출 할 때 어떤 타입을 기대한다고 말합니다. (그렇다고해서 '넓은'과 '안에'라고 불릴 필요는 없습니다. 그렇지만 그들은 괜찮습니다.) – zzxyz
선언과 정의가 다르기 때문에 수정해야합니다. 링커가 함수를 찾지 못할 것이며, 그것이 다른 오버로드라고 생각할 것입니다. 함수를 호출 할 때 - 변수 만 전달하면 안됩니다 :'populateList (wide, in);' –