0

I really don't know how to explain this neither to a browser nor to stackoverflow, so i'm going to just type an example.

vector<int> x;
x.push_back(5);

How do you call the fact that i used a dot to tell the function which vector i wanted it to operate with?

I tried googling it with no luck. I have no programmer friends to explain this to in person.

bulug
  • 39
  • 3
  • 2
    If you want to learn C++ good sources are : [a recent C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) or from [learncpp.com](https://www.learncpp.com/) that site is decent and pretty up to date. Then use [cppreference](https://en.cppreference.com/w/) for reference material (and examples). When you have done all that keep using [C++ core guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) to keep up to date with the latest best practices since C++ keeps evolving. – Pepijn Kramer Jun 07 '23 at 03:46
  • 2
    You really need to find a decent textbook to learn the basics of C++. The concepts to answer your question are covered early on in most (even bad ones) introductions to C++. No point in using SO for such basic learning (SO is not an introductory site - it's for people who already know the basics to ask specific questions). You won't have much luck with google unless you do a specific search - which you won't be able to do well before you know the basics. If you had any competent programmer friends, they would have learned using a decent introductory text, and would advise you to do the same. – Peter Jun 07 '23 at 04:01
  • `.` is sometimes called the *member access operator*. But `->` is also sometimes called the same thing. – john Jun 07 '23 at 04:58
  • 3
    I think bulug's question makes it perfectly clear that he understands what the quoted code does. He just want to know what the operator is called. – john Jun 07 '23 at 05:00
  • I am actually studying from principles and practice of programming by stroustrup, i was left with this doubt because he introduces vector manipulation through functions but does not say how the dot thing is called. I thank you all for the resources, and clarifications you’ve provided. This community is a blessing – bulug Jun 07 '23 at 10:56

2 Answers2

6

The . operator is a member access operator called the "member of object" operator. With this operator, you can access all data members and member functions of the class. In this case, you are accessing the push_back member function of the class and you are calling it.

The () is the function call operator. It can be applied to both non-member functions (i.e. functions that do not belong to a class) and member functions.

Andreas Wenzel
  • 22,760
  • 4
  • 24
  • 39
2

The combination of

something.function(arguments)

is called a member function call.

j6t
  • 9,150
  • 1
  • 15
  • 35