Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 20th, 2005, 10:47 PM   #1
BrinyCode
Newbie
 
Join Date: Nov 2005
Posts: 11
Rep Power: 0 BrinyCode is on a distinguished road
What are these symbols ---> ::

What are these symbols in C++, I can't find an explaination for them ---> ::
BrinyCode is offline   Reply With Quote
Old Nov 20th, 2005, 10:59 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
I can't remember what it's called, PHP's debugger calls it a "PAAMAYIM_NEKUDOTAYIM".

Basically what it's used for is defining class functions outside of the class delcaration...

Example:

class test {
	public:
		inline test();
};

inline test::test() {
	// Here's some code..
}
__________________

tempest is offline   Reply With Quote
Old Nov 20th, 2005, 11:33 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 646
Rep Power: 4 Jessehk is on a distinguished road
the :: is the ownership operator. For example:

class Test
{
	private:
		int number;
	public:
		Test(int x)
			: number(x) {}
};

In this case, anything beginning with ...

Test::

would tell the compiler that it belonged to the Test class.

For example:

Test::number //bad example, because number is private

This can also apply to namespaces. Hope that helped


EDIT: I think more examples are in order.

class Test
{
	private:
		int number;
	public:
		Test(int);
		void mult(int);
		void print() const;
};

//using the ownership operator to define class methods
//first the constructor
Test::Test(int x)
{
	number = x;
}

//then the mult (multiply) method
void Test::mult(int x)
{
	number *= x;
}

//then maybe a display method
void Test::print() const
{
	std::cout << number << std::endl; //ownership operator used to denote namespace ownership as well
}

Feel free to pm if you still don't understand
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!

Last edited by Jessehk; Nov 20th, 2005 at 11:43 PM.
Jessehk is offline   Reply With Quote
Old Nov 21st, 2005, 12:27 AM   #4
BrinyCode
Newbie
 
Join Date: Nov 2005
Posts: 11
Rep Power: 0 BrinyCode is on a distinguished road
Well you made a couple good points that lead for me to ask:

1. Classes ( I this as it name it implies)
2. ownership operator (Does it really mean ownership?)
3. Also why do we see "std" with it some times.



Just to let you know I am not Pro, just in video game development and relatively new to the C++ language in case I sound like a noob. That's because I am a noob when it comes to the C++ language.
BrinyCode is offline   Reply With Quote
Old Nov 21st, 2005, 1:12 AM   #5
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 316
Rep Power: 4 andro is on a distinguished road
Send a message via AIM to andro
Ermm, :: is the scope resolution operator.
andro is offline   Reply With Quote
Old Nov 21st, 2005, 3:06 AM   #6
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Well std is a namespace and as Jessehk mentioned, it applies to namespaces aswell.

So cout is a function to output something. It is declared in the std namespace, so you'd use this:
std::cout<<"blah";

But you don't have to use the std:: part if you declare the namespace globally using this:
using namespace std;
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Nov 21st, 2005, 4:09 AM   #7
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by BrinyCode
Well you made a couple good points that lead for me to ask:
[b]
1. Classes ( I this as it name it implies)
Are you asking what classes are, or have I just misread what you've said?

Classes are the blueprints of objects. Objects are structures that contain both data and code.

You really need to understand about classes and objects if you're going to code in C++.
Arevos is offline   Reply With Quote
Old Nov 21st, 2005, 7:51 AM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
As Andros said, "::" is the scope (not ownership) resolution operator. With that terminology, you should be able to find what you were looking for.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 3:27 PM   #9
BrinyCode
Newbie
 
Join Date: Nov 2005
Posts: 11
Rep Power: 0 BrinyCode is on a distinguished road
Quick question, why the word scope and if we did not use them what would happen?
BrinyCode is offline   Reply With Quote
Old Nov 21st, 2005, 4:10 PM   #10
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 266
Rep Power: 4 Cache is on a distinguished road
Here are some definitions of the word "scope":

1. Breadth or opportunity to function.
2. The area covered by a given activity or subject.

I'm very new to programming, so if I can understand "why the word scope" from it's definition, I'm sure you can too. I think from that you can also assume what may happen if you try to use an object without bringing it into scope, from outside it's "opportunity to function", the "area covered by a given activity or subject".

Perhaps someone else will give you a more technically sound answer but I think it's good practice to look at the definition of words you use if you don't understand why you are using them.
Cache is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:42 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC