By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

What's wrong with this?

P: n/a
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>::operator
()(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
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sop3k wrote:
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>::operator
()(class CStr &) const'
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.
####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;
}


--
Best regards,
Andrey Tarasevich

Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.