Question

I have this piece of code:

std::map< int, std::pair<int, int> > m;
for ( std::vector<Pass*>::const_iterator passIt = it->GetPasses().begin(); passIt != it->GetPasses().end(); ++passIt )
{
    m.insert( std::make_pair((*passIt)->GetType(), (*passIt)->GetAgeRange()) );
}
--> ages.push_back( new std::istringstream(SerializeAges(m)) ); <--

The marked line yields this error:

undefined reference to `SerializeAges(std::map<int, std::pair<int, int>, std::less<int>, 
 std::allocator<std::pair<int const, std::pair<int, int> > > > const&)'

Declaration:

 static std::string SerializeAges(const std::map< int, std::pair<int, int> > &ageMap);

Definition:

inline std::string SerializeAges(const std::map< int, std::pair<int, int> > &ageMap)
{       
}

Signatures of other called functions:

std::pair<int, int> GetAgeRange() const;

I have no idea what goes wrong here.

EDIT: sorry, Type is an enum, so what GetType() returns is implicitly converted to an int.

Was it helpful?

Solution

From the comments, it seems that it's a class member. In that case, the definition will need to use the qualified name:

inline std::string WhateverTheClassIsCalled::SerializeAges(const std::map< int, std::pair<int, int> > &ageMap)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^

Without that, the definition declares a separate non-member function with the same name, and the member remains undefined.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top