0
votes

When I'm trying to read a file with a function

void readFile(string fileName, string* anArray) {
    unsigned int lineCounter = 0;
    ifstream inFile = ifstream(fileName);

    while (!inFile.eof()) {
        string fileLine;
        inFile >> fileLine;
        if (!fileLine.empty()) {
            anArray[lineCounter] = fileLine;
            ++lineCounter;
        }
    }
    inFile.close();
}

I get the error below, which I assume is because of the pointer on the string array ?

1>Main.obj : error LNK2019: unresolved external symbol "void __cdecl resource::readFile(class std::basic_string,class std::allocator >,class std::basic_string,class std::allocator > *)" (?readFile@resource@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAV23@@Z) referenced in function _main

1
Pretty sure that's not the full error. - Joseph Mansfield
ups.. update incomming - Xerath
It is complaining about not being able to find the definition of resource::readFile. Which source file is it defined in, and are you linking to it? - Vaughn Cato
Is readFile supposed to be a member function defined outside of the class resource? If so you likely meant void resource::readFile(...) {. - Joe
Yes yes, omg I left out the part... - Xerath

1 Answers

2
votes
void readFile(string fileName, string* anArray) {

This is the definition of a member function, but you forgot to write the class name.

void resource::readFile(string fileName, string* anArray) {

As you have it now, you've defined a new function in the global namespace that has nothing to do with resource, so when main tries to use resource::readFile, the definition cannot be found.