0

I have the following class

class Intern
{
    public:
        Intern();
        Intern(Intern& obj);
        ~Intern();
        
        Form*   makeForm(std::string name, std::string target);

        typedef std::map<std::string,Form*(Intern::*)(std::string)> map_t;

        Form*   makeShrub(std::string target);
        Form*   makeRobot(std::string target);
        Form*   makePres(std::string target);

        const map_t     construct_map(void);
        const map_t&    return_map(void);
};

Form is another class that I won't include in my question because it is irrelevant here. The member function I am having trouble with is construct_map:

#include "Intern.hpp"

typedef std::map<std::string,Form*(Intern::*)(std::string)> map_t;

const map_t Intern::construct_map(void)
{
    map_t m;

    m["shrubbery creation"] = &Intern::makeShrub;
    m["robotomy request"] = &Intern::makeRobot;
    m["presidential pardon"] = &Intern::makePres;
    return m;
}

I have used maps before and I have always used pretty much the same code. However, I get the following error:

Undefined symbols for architecture x86_64:
  "Intern::makePres(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      Intern::construct_map() in Intern.o
  "Intern::makeRobot(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      Intern::construct_map() in Intern.o
  "Intern::makeShrub(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      Intern::construct_map() in Intern.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't now why am I getting this error. Can someone help me?

Edit I define makeShrub, makeRobot and makePres in the same document as construct_map, just above it

kubo
  • 221
  • 1
  • 8
  • 1
    Where do you define `makeShrub`, `makeRobot` and `makePres`? – NathanOliver Sep 13 '21 at 17:29
  • "I don't now why am I getting this error." This is the wrong mindset for debugging. Tell me why you *know* that you *should not* get this error, and then I can try to tell you why you are wrong. If you don't know that, then you need to think about why that is - what are the steps you should take in order to be confident? – Karl Knechtel Sep 13 '21 at 17:30
  • Can you update your post with a [mre] that shows how they are defined? If they are defined right before this function, then there is no way you should be getting this type of linker error. – NathanOliver Sep 13 '21 at 17:32

0 Answers0