mercredi 12 août 2020

C++ Undefined reference to vector function

I have a main file, a h file and an implementation file as shown below

main

#include <iostream>
#include "driver.h"
#include <sstream> 
#include <fstream>

int main(int argc,char* argv[]){

std::vector<Band> bandsVec = readbandFile(argv[1]);
}

h

#include <string>
#include <vector>

#ifndef DRIVER_H
#define DRIVER_H

struct Band {
std::string bandName;
std::string listofMembers;
};
struct Muscian {
char code;
std::string name;
int maxLimit;
int impact;
int variability;

};

struct Judge {
std::string name;
int toughness;
int moodiness;
};
#endif

std::vector<Band> readbandFile(std::string fileName);

implementation

#include "driver.h"
#include <iostream>

std::vector<Band> readbandFile(std::string fileName)  {
//code here
}

When i attempt to compile the files i get an error

 g++ main.cpp implementation.cpp -o RUN

undefined reference to `readbandFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status

From what i can see i have included the declaration in the h and the definition in the implementation so im not sure as to why im recieving this error.

To also note: when i remove = readbandFile(argv[1]); from main the code compiles

Aucun commentaire:

Enregistrer un commentaire