Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Multiple Definitions Error

Tags:

c++

I have something like this in my code:

namespace A {
namespace B {

void
GetLine(std::istream& stream, std::string& line)
{
    line.clear();
    while (stream.good()) {
        std::getline(stream, line);
        boost::trim(line);
        if (not line.empty()) break;
    }
    boost::to_upper(line);
}

}
}

And I get multiple definition error whenever I call A::B::GetLine. Any Ideas why?

(The code is at work, so I will try to give out specific snippets if you need more info, but I can't just pase the entire code here).

like image 960
Amir Rachum Avatar asked Apr 09 '26 12:04

Amir Rachum


1 Answers

You almost certainly included the code in multiple headers, rather than declaring in a header and defining in a source file. You need to declare the function inline, template it, or move the definition into a source file but leave the declaration in a header.

like image 88
Puppy Avatar answered Apr 11 '26 22:04

Puppy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!