0

I've started learning Classes in C++ and have come across this :: operator. I have no idea what it means and how/when to use it. It was in every piece of C++ code I'd ever seen. The tutorial I watched didn't explain what it is. Could anyone explain?

Serket
  • 3,785
  • 3
  • 14
  • 45
  • 9
    Pick up a book and read. YouTube videos are not a good place to start learning. – CroCo May 03 '20 at 22:02
  • 1
    `::` identifies a member of a class, namespace, etc. Can you share a piece of code so we have something on which to base any answers? I would also agree that written content is far better than a YouTube video; whilst a video generally demonstrates how to write a piece of code, it is not a good medium for actually discussing the underlying principles. – nanofarad May 03 '20 at 22:02
  • 1
    It's simply for scope resolution. You can have for example two functions with the name "cout" , one std::cout and one whatever_you_want::cout . – Parsa Mousavi May 03 '20 at 22:03
  • @ParsaMousavi But what is the use/purpose of it?? – Serket May 03 '20 at 22:04
  • @Serket It prevents name clash in your code which can result in unwanted behavior. – Parsa Mousavi May 03 '20 at 22:09
  • @Serket It's possible to live without it , for example in C there is no namespace.But it's there to help you write a better code. – Parsa Mousavi May 03 '20 at 22:12

0 Answers0