What's wrong with this?

Discussion in 'C++' started by sop3k, Dec 2, 2003.

  1. sop3k

    sop3k Guest

    Compiling the code below, by VC++ 6.0 I get an error like this:

    visual c++\vc98\include\functional(263) : error C2562: '()' : 'void'
    function returning a value
    visual c++\vc98\include\functional(262) : see declaration of '()'
    visual c++\vc98\include\functional(263) : while compiling
    class-template member function 'void __thiscall
    std::mem_fun_ref_t<void,class CStr>::eek:perator
    ()(class CStr &) const'

    ####Code####

    #include<iostream>
    #include<algorithm>
    #include<functional>
    #include<vector>
    #include<string>

    class CStr{
    std::string s;
    public:
    CStr(std::string sl) { s= sl;}
    void Print(){ std::cout<<s<<std::endl; }
    };

    char t[10];
    std::vector<CStr> v;
    std::string el;

    int main(){
    for(int i=0;i<10;i++){
    el+=itoa(i,t,10);
    v.push_back(el);
    }

    std::for_each(v.begin(),v.end(),std::mem_fun_ref(&CStr::print));
    return 0;
    }

    What's wrong?

    With Best Regards
    Tomasz Sobkowiak
     
    sop3k, Dec 2, 2003
    #1
    1. Advertisements

  2. It is a known problem of this compiler. Change your 'CStr::print'
    function to return a dummy value of type, say, 'int' and the code will
    compile.
     
    Andrey Tarasevich, Dec 2, 2003
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.