What's wrong with this?

S

sop3k

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
 
A

Andrey Tarasevich

sop3k said:
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'

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;
}
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top