map<string, vector<int> >                                    // 42
     xref(istream& in,                                       // 43
          vector<string> find_words(const string&) = split)  // 44


this is a cross-ref program that's written in the book, the exercise told me to create an improved feature for it. So, before I start with my work, I need to organise the code of original program in it's own file. but, when I compile the code(without any modification or anything) it won't compile with the error above.

I believed that the code filled with typo or something but I can't find any, it's new code for me anyway, so I can't really tell which part at fault. Pls help, ty.

I don't know what you're talking about "definition of the default argument "shift"?".

if you mean split fuction code, here:

vector<string> split(const string& str)
    typedef string::const_iterator iter;
    vector<string> ret;

    iter i = str.begin();
    while (i != str.end()) {

        // ignore leading blanks
        i = find_if(i, str.end(), not_space);

        // find end of next word
        iter j = find_if(i, str.end(), space);

        // copy the characters in [i, j)
        if (i != str.end())
            ret.push_back(string(i, j));
        i = j;
    return ret;

this is also directly copy/paste from the books, and it's working on previous chapter, so I doubt the fault would be here. :S

The error message is saying that you specified the default value for find_words both in the declaration and the definition of the function. You're only supposed to do it in the declaration.

tyvm, it works, I never knew about this before, I did test the code before but on a single file, and the error never come out. Maybe due to its definition also represent its declaration or something? Plus, this never told in the book so, sorry for trouble.

anyway, ty again for help ^^

This article has been dead for over six months. Start a new discussion instead.