I have this C++ snippet that I am trying to understand:
in .hh file:
class A
{
private:
//recordDelimiter is a '+' character
// I can do this because char is an integral type!
static const char recordDelimiter = '+';
void f()
{
....
//serializedData is a std:;string
//Get number of times A::recordDelimiter is found i.e. Number of objects
// Non-Functional
int times = (int) std::count (serializedData.begin(), serializedData.end(), A::recordDelimiter);
// Functional
const char recDel = A::recordDelimiter;
int times = (int) std::count (serializedData.begin(), serializedData.end(), recDel);
// Functional
int times = (int) std::count (serializedData.begin(), serializedData.end(), '+');
....
}
};
From std::count reference this is the signature of the function:
template <class InputIterator, class T>
typename iterator_traits<InputIterator>::difference_type
count (InputIterator first, InputIterator last, const T& val)
So I don't see why using A::recordDelimiter
instead of '+'
is a problem. Compiling gives me undefined reference to
A::recordDelimiter'`
So my question is basically, why is my non-functional code above not functional? and how come doing this :
const char recDel = USerializer::recordDelimiter;
and then pass it to std::count works?