![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 11
Rep Power: 0
![]() |
What are these symbols ---> ::
What are these symbols in C++, I can't find an explaination for them ---> ::
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
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..
}
__________________
|
|
|
|
|
|
#3 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 646
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2005
Posts: 11
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#5 |
|
Professional Programmer
|
Ermm, :: is the scope resolution operator.
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
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++. |
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Nov 2005
Posts: 11
Rep Power: 0
![]() |
Quick question, why the word scope and if we did not use them what would happen?
|
|
|
|
|
|
#10 |
|
Hobbyist
Join Date: Sep 2005
Posts: 266
Rep Power: 4
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|