0
votes

I decided to try and code a basic program but i keep getting this eror:

/tmp/cczXwiYT.o: In function main': main.cpp:(.text+0xd8): undefined reference toutils::checkInputs(std::__cxx11::basic_string, std::allocator >, std::__cxx11::basic_string, std::allocator >)' collect2: error: ld returned 1 exit status

Im new to c++ (just saying)

I tried to change the type from void to int to boolean etc.

main.cpp

#include <iostream>
#include <string>
#include <fstream>
#include "utils.h"

int main(){

    utils u;

    std::string a = "a";
    std::string b = "a";
    u.checkInputs(a,b);

    return 0;
}

utils.cpp

#include <iostream>
#include <string>
#include <fstream>

#include "utils.h"

using namespace std;

utils::utils(){};

void checkInputs(string userInput, string target){
    cout << "hey i work" << endl;
}

utils.h

#ifndef UTILS_H
#define UTILS_H

    #include <iostream>
    #include <string>
    #include <fstream>

    using namespace std;

class utils
{
    public:
        utils();
        void checkInputs(string userInput, string target);
};

#endif 

Thanks for the help =)

1
Typo: change void checkInputs... to void utils::checkInputs... in utils.cpp. - Paul Sanders
And please ditch the using namespace std; line. - Chimera
@Chimera: The one in the .h, right? (While we’re at it, please name C++ header files .hpp, .hxx, or .hh.) - Davis Herring
@DavisHerring Now you have the hang of it! :-) - Chimera
Sanders thank you I will try that - Petereo

1 Answers

0
votes

Thank you everyone as said by PaulSanders "Typo: change void checkInputs... to void utils::checkInputs... in utils.cpp." It fixed my problem just fine =)