ld: symbol(s) not found for architecture x86_64 error on array of structs [closed]

StackOverflow https://stackoverflow.com/questions/23355372

  •  11-07-2023
  •  | 
  •  

문제

running into this odd error when passing a type def of array of structs to a function. My code is below:

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;


const int MAXRECORDS = 50;
struct Grades                             // declares a structure
{
    char name[NAMESIZE + 1];
};

typedef Grades gradeType[MAXRECORDS];  


void ReadIt( ifstream &i, gradeType gradeRec, int &h);

int main()

{    
     ifstream indata;
     int numRecord;                // number of records read in
     gradeType studentRecord; 

     /* Some stuff */
     ReadIt(indata, studentRecord, numRecord);               

    /* Other Stuff*/
    return 0;
}



void readIt(ifstream &inData, gradeType gradeRec, int &total)

{
    // never make it here, does not compile
}

g++ gives the following error:

Undefined symbols for architecture x86_64:
"ReadIt(std::__1::basic_ifstream >&, Grades*, int&)", referenced from: _main in Grades-10db96.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

도움이 되었습니까?

해결책

C++ is a case-senstiive language. readIt is not the same as ReadIt.

다른 팁

in the declaration you're using gradeRec whereas in the definition you're using gradeRec&. Those are two different symbols.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top