0

I am hoping someone can help me understand this.

I ran into this code:

vector<string> split_string(string input_string) {
    string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
        return x == y and x == ' ';
    });

I am not sure what the :: represents, I have never seen it used this way before. Maybe it is an alternative to using string.iterator?

Also, I am a bit confused regarding to member types in a class on cppreference.com:

Member Types

string is a type of class, how do all these member types relate to string, or any other class's relationship with its own inherit member types?

I would really love some guru advice here.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
T-Bone
  • 45
  • 4
  • 1
    Also see: https://www.geeksforgeeks.org/scope-resolution-operator-in-c/ – NathanOliver Oct 15 '19 at 21:18
  • 1
    This is a good question but it's also super fundamental to C++ and a sign you need a good reference to work from. It'll take a few hours to familiarize yourself with the basics of C++, but once you do things will make a lot more sense. Stumbling along with no idea what's going on and trying to intuit it as you go is not an effective approach here, C++ is way too complicated to do that. – tadman Oct 15 '19 at 21:21
  • 1
    Also, is it okay to upload snapshots of web-sites? Would not including a link to the page in cppreference.com be more appropriate? – Happy Green Kid Naps Oct 16 '19 at 02:11
  • it's right there in std::vector and std::string. You didn't see it because you're `using namespace std` which is a [bad practice](https://stackoverflow.com/q/1452721/995714). And as said above, you shouldn't post an image of text [Why are images of text, code and mathematical expressions discouraged?](https://meta.stackexchange.com/q/320052/230282) – phuclv Oct 16 '19 at 03:43

1 Answers1

0

In this instance, iterator is a class defined inside of string. This segment of code demonstrates how iterator would be defined relative to string

#include <iostream>
class Outer{
  public:
  class inner{
    public:
    int num;
  };
};
int main() {
  Outer::inner i;
  i.num = 0;
  std::cout << i.num;
}

The goal behind the nested classes is encapsulation, where everything the string does and its related nested classes are kept separate and/or private from everything else in the name space.

As NathanOliver pointed out, you really need a C++ book to go into depth with all of these members.

Phles
  • 327
  • 3
  • 10