6 Replies - 264 Views - Last Post: 07 May 2011 - 12:59 PM Rate Topic: -----

#1 Ticon  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 320
  • Joined: 20-August 09

What is this :: ?

Posted 07 May 2011 - 12:41 PM

Hello! I am book taught, so what the book doesn't explain I ask here. I'm a bit confused on what :: is signifying. this is the program that is listed, im going to leave out what I think is useless to you
Spoiler

So the following confuses me
int Cat::GetAge()
and void Cat::Meow() along with anything that has this::that . Thanks for reading and im sorry if ive thrown in useless things into this code listing. Any feedback is very much so appreciated so thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: What is this :: ?

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4003
  • View blog
  • Posts: 12,354
  • Joined: 25-December 09

Re: What is this :: ?

Posted 07 May 2011 - 12:46 PM

Quote

I'm a bit confused on what :: is signifying.


That is called the scope resolution operator.

Quote

So the following confuses me
int Cat::GetAge() and void Cat::Meow()


In these items the :: is telling the compiler that GetAge() is a member function belonging to the Cat class.

Quote

std::cout


In this case the :: is telling the compiler that cout is located in the std namespace. See this link for namespaces.

Jim
Was This Post Helpful? 1
  • +
  • -

#3 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,140
  • Joined: 14-September 07

Re: What is this :: ?

Posted 07 May 2011 - 12:47 PM

:: is the scope resolution operator.

In a nutshell:

Owner::thing


In this case these a functions belonging to the Cat class, but you also use :: when using static variables and namespaces.
Was This Post Helpful? 1
  • +
  • -

#4 Ticon  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 320
  • Joined: 20-August 09

Re: What is this :: ?

Posted 07 May 2011 - 12:50 PM

Quote

In these items the :: is telling the compiler that GetAge() is a member function belonging to the Cat class.

is this actually needed, or is this a purist method?
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is offline

  • member icon


Reputation: 4003
  • View blog
  • Posts: 12,354
  • Joined: 25-December 09

Re: What is this :: ?

Posted 07 May 2011 - 12:54 PM

Yes it is actually needed.


Jim
Was This Post Helpful? 1
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: What is this :: ?

Posted 07 May 2011 - 12:56 PM

Quote

is this actually needed, or is this a purist method?
It's required. Think:

class Foo {void bar();};

void bar();



There's two functions named bar. Are they different? Yes. One is a member function of class Foo, the other is a regular function.
Was This Post Helpful? 1
  • +
  • -

#7 Ticon  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 320
  • Joined: 20-August 09

Re: What is this :: ?

Posted 07 May 2011 - 12:59 PM

:) thank you all very much, this has puzzled me for days! Much respect to you all
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1