The following code will compile. I have one line commented out because it
won't compile. Why can I not do this:
//set<string>::it erator iterator = s->begin();
Why do I have to deference the set when I receive it as a pointer? Is that
just the way we are supposed to do it, or am I missing something?
-------------------------------------------------
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<stringStrin gSet;
void zoot(set<string * s);
int main()
{
set<strings;
s.insert("aaa") ;
s.insert("bbb") ;
zoot( &s );
return 0;
}
void zoot(set<string * s )
{
// This won't compile - why?
//set<string>::it erator iterator = s->begin();
// dereference s, use s1, and it compiles
set<strings1 = *s;
for( set<string>::it erator iterator1 = s1.begin();iter ator1 !=
s1.end();iterat or1++)
{
cout << *iterator1;
}
}
won't compile. Why can I not do this:
//set<string>::it erator iterator = s->begin();
Why do I have to deference the set when I receive it as a pointer? Is that
just the way we are supposed to do it, or am I missing something?
-------------------------------------------------
#include <iostream>
#include <set>
#include <string>
using namespace std;
typedef set<stringStrin gSet;
void zoot(set<string * s);
int main()
{
set<strings;
s.insert("aaa") ;
s.insert("bbb") ;
zoot( &s );
return 0;
}
void zoot(set<string * s )
{
// This won't compile - why?
//set<string>::it erator iterator = s->begin();
// dereference s, use s1, and it compiles
set<strings1 = *s;
for( set<string>::it erator iterator1 = s1.begin();iter ator1 !=
s1.end();iterat or1++)
{
cout << *iterator1;
}
}
Comment