Aug 25, 2012 at 9:31pm UTC
Hey all,
The error is:
Error 1 error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion).
Code:
classes :
class Coogle
{
private:
vector<map<string,unsigned int>> map_vec ;
public:
Coogle(const string s);
~Coogle();
int getNumOfWords() const;
void loadFile(const string filename);
};
class new_map_vec
{
private:
map<string,unsigned int> merge_map;
public:
void merge_maps(vector<map<string,unsigned int>> map_vec);
void get_map(map<string,unsigned int> &user_map);
new_map_vec();
~new_map_vec();
};
The problem accured when I started using these functions:
void new_map_vec::get_map(map<string,unsigned int> &user_map)
{
copy(merge_map.begin(),merge_map.end(),user_map.begin());
};
int Coogle::getNumOfWords() const
{
new_map_vec map_cont;
int count=0;
map<string,unsigned int> temp;
map<string,unsigned int>::iterator iter;
map_cont.get_map(temp);
for(iter=temp.begin();iter!=temp.end();iter++)
count++;
return count;
};
why is that happening ?? please help
Thank you !!
Aug 25, 2012 at 9:58pm UTC
The value_type for std::map is defined the following way
typedef pair<const Key, T> value_type
So you can not assign one object of the value_type to another object.
Last edited on Aug 25, 2012 at 9:58pm UTC
Aug 25, 2012 at 11:19pm UTC
sorry ne555, but I didn't understand what u said :(
vlad what should I do, merge_map is private and I need to use it in another class function... so I wrote the get_map function.
send iterator to function ?
Aug 26, 2012 at 2:33am UTC
The key is used to construct the map, so you can't happily change it.
I don't understand what you are trying to accomplish. For what matters, your map is empty when you call that function.
1 2 3 4 5 6 7
vector<map<string,unsigned int > > new_map_vec::get_a_copy_of_my_guts() const {
return merge_map;
}
void new_map_vec::unite_the_kingdom( const vector<map<string,unsigned int > > &m ){
merge_map.insert( m.begin(), m.end() );
}
Tell what you want to do, not how you are doing it (because you are doing it wrong)
Last edited on Aug 26, 2012 at 2:34am UTC