class child:public BASE
{
public:
child ();
///MY PROBLEM is how access attributes of source and BASE to use as parameters //to fill my multimap
void ADD(BASE& a){
multimap <BASE, string> abo;
typedef pair <BASE,string> duo;
typedef multimap < BASE,string> ::iterator it;
//////////////////////////////::
///ALL OF THIS DIDN'T WORK FOR ME
// abo.insert({ a.ZZ, a.N });
// abo.insert({ a.ZZ, a.N});
// BASE(a.ZZ,a.N) = abo[a.ZZ] ;
// abo[BASE(a.ZZ,a.N)]=a.ZZ;
}
}
/src/children.cpp:32:40: error: no match for call to ‘(std::multimap<BASE, const std::__cxx11::basic_string<char> >) (const string&)’
32 | abo[BASE(a.ZZ,a.N )] = abo(a.ZZ);
* There is no operator[]. Therefore, you can't call abo[x]
* There is no operator(). Therefore, you can't use abo as functor. The abo(y) is not possible. The error message says that.
* For adding elements there is insert(). See http://www.cplusplus.com/reference/map/multimap/insert/
Hence: abo.insert(z);
What type must the z have?
iterator multimap::insert (const value_type& val);
In your case the value_type is duo (aka std::pair<BASE,std::string>)
How does one create a duo object? You need a BASE object and string object:
1 2 3
BASE a;
string w;
abo.insert( duo(a,w) );
You should know yourself what string you want. Your Add() function gets only a BASE as argument.
Note:
Internally, the elements in a multimap are always sorted by its key following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare).
For your multimap the Compare is less<BASE>.
Therefore, this must be possible:
1 2
BASE a, b;
if ( a < b )
For that you need booloperator< ( const BASE&, const BASE& );
Is this necessary because my MULTIMAP have two defferents costum parameters?if so what is the implementation of operator operator< and operator== in this case.
THE AIM IS TO HAVE AN ALPHABETICAL ORDER
this is my implimentation it stores witch means abo.insert( duo(a ,a.info) ) worked for me
but when i wanna see the contains by using iterator it does not compile
Yes for sure int is type not a variable but i tried to understand what do you mean .
All i know is "it" is an iterator pointer whereby we can navigate through containers of a multimap.
Unfortunately it doesn't work here it is the output:
error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘source’)cout << it->second<<"----" << endl;
| ~~~~ ^~ ~~~~~~~~~~
| | |
| | source
| std::ostream {aka std::basic_ostream<char>}
the implementation is
1 2 3
for(multimap <BASE,source> ::iterator it=abo.begin(); it!=abo.end(); ++it){////////////HERE IS MY PROBLEM
cout << it->first<<"----" << endl;
cout << it->second<<"----" << endl;
The aime of this is to create a Base class containing name as a private string and a struct containing lastname,adresse, phone but BASE class contains "source info " as private attributes so we want to store those atributes in nient we want to use Base as a key wich can reprsent name i don't know if this is
convinient <BASE,source> i dont know may be this is the best <BASE,string>
yes it is done but unfortunately that wasn't the expected .
What is expected is to have as first ->abo only name of subscriber as a key and in the other hand of the map i 'm supposed to have the information of that subscriber and what i have as out put looks like this .
|WILLIS|HOLLYWOOD|0645454545
----
JIM|9AVENUE|9900900898
////while i want a name in the key i know i can manage the things by changing the key as type string and pointing a.nom but the use of BASE as a key is a MUST .
i think the a part of problem is here abo.insert( duo(a ,a.info) ) we can't point a.name in the first parameter because it will be type string and i want BASE to be my key as a name of subscriber.
Think of a table with two columns.
The rows sorted by the first column.
The values in the first column are unique; no same value twice.
The second column has no such restrictions.
Some languages call such table "dictionary".
Why do you have the data in map at all? When you can find a BASE, you can already read its 'info'. You don't need to repeat the 'info' in separate column.
I think of a second a class and a MAP for further functions.but the problem is solved now and thank you so much .Now my problem is when i have a string forme and i want to split it by specific character.
my form looks like this string S=" name|lastname|adresse|phone"
I used getline (ss ,line,'|') so i think we should have four strings.what i want to do is to split it by only two elements and by the first '|' met.so the string will be in two parts rather than four like before string1= name string2 =lastname|adresse|phone.
i'm stucked.