undefined reference

Hey all, working on a problem from exercism.io and am getting the error
"undefined reference to `nucleotide_count::counter::nucleotide_counts()"

Thanks in advance for the help, I looked into linking errors, classes in namespaces, and anything else I could think of but cant find a solution.

Also the code isnt finished yet, I am just trying to get past this error message.

Nucleotide_count.h
1
2
3
4
5
6
7
8
9
10
11
#include <map>

namespace nucleotide_count {
    class counter{
        private:
            std::string dna;
        public:
            counter(const std::string &s) : dna(s) {}
            const std::map<char,int> nucleotide_counts();
    };
} 



Nucleotide_count.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "nucleotide_count.h"

namespace nucleotide_count {
    const std::map<char, int> counter::nucleotide_counts()
    {
        std::map<char, int> map;
        for(auto &i : dna){
            const auto j = map.find(i);
            if(j == map.end())
                map.insert(std::make_pair(i,1));
            else
                j->second++;
        }

        return map;
    }
} 



test.cpp
1
2
3
4
5
6
7
8
#include <iostream>
#include <string>
#include "nucleotide_count.h"

int main()
{
    nucleotide_count::counter test("aslkdja");
}
Last edited on
Is Nucleotide_count.cpp in your project file?

Your project needs to list all the source files you want to compile.

When you built the program, did you see
Compiling Nucleotide_count.cpp
Compiling test.cpp
Linking...
Topic archived. No new replies allowed.