You can include your own questions too.
I haven't taken any classes for programming. Everything I know is from tinkering around, some short lived google searches and from my cancerous experience with gamemaker.
So I want to be good, in fact I want to be the best, but right now I don't understand anything.
What do the double colons mean? It's for a project I'm editing. (someone else wrote the code) This is C++
[img]http://anyhub.net/file/1NnB-doublecolon.jpg[/img]
Don't tell me to scurry back to gamemaker, because to accomplish what I want to accomplish, gamemaker is not a practical tool.
I do want to get into programming robotics. Preferably Nano-robotic colonies.
Automated technologies make it easier being human. There are somethings I wish to automate and hasten.
Exploring the world on a micro level through Nano-robotics offers the opportunity to provide greater efficiency to technology. So yeah, I'm into that stuff. Any guidance would be swell
:: is for accessing namespaces and [del]static[/del] members of a class. Without anything in front of it, it's the global namespace.
[QUOTE=raBBish;27988441]:: is for accessing namespaces and static members of a class. Without anything in front of it, it's the global namespace.[/QUOTE]
"->" are for pointers right?
and what are the "_" before the variable names? I couldn't find an answer for this anywhere
:: is the namespace qualifier (google it). ::a etc qualifies it as the a in the global namespace:
[code]
int a = 5;
void f()
{
int a = 7;
std::cout << a << " " << ::a;
}
[/code]
[QUOTE=Haley;27988459]"->" are for pointers right?[/QUOTE]
Yep.
[QUOTE=Haley;27988459]and what are the "_" before the variable names? I couldn't find an answer for this anywhere[/QUOTE]
It's just part of the name, some people use it to denote private members.
[QUOTE=r4nk_;27988467]:: is the namespace qualifier (google it). ::a etc qualifies it as the a in the global namespace:
[/QUOTE]
So this will make:
16 5 7
right?
[code]
int a = 5;
void f()
{
int a = 7;
g();
}
void g()
{
int a = 16;
std::cout << a << " " << ::a << " " << f::a;
}
[/code]
@rabbish
So this would not make sense
[code]
overHere_int->3;
[/code]
But this would?
[code]
overHere_int->these_Ints_overhere;
[/code]
And if we want the pointer value to enter into a function we'll do this
[code]
dont_mind_me_just_calling_my_function(&overHere_int);
[/code]
You can't access f::a from g. Though if you could, yes.
No you can't do that, the a in function f is only accessible from within the function (not from within functions that are called inside f..). but your output would be right if you could.
[QUOTE=r4nk_;27988530]No you can't do that, the a in function f is only accessible from within the function (not from within functions that are called inside f..). but your output would be right if you could.[/QUOTE]
oh yeah. cuz g() could be used outside of f... and that would leave room for errors
but I can't, so it's pointless @_@
if I wanted to pass the value in i'd have to do so with an argument or by putting it in a global variable, correct?
@rabbish
So this would not make sense
[code]
overHere_int->3;
[/code]
But this would?
[code]
overHere_int->this_Int_overhere;
[/code]
And if we want the pointer value to enter into a function we'll do this
[code]
dont_mind_me_just_calling_my_function(&overHere_int);
[/code]
[QUOTE=Haley;27988502]So this would not make sense
[code]
overHere_int->3;
[/code]
But this would?
[code]
overHere_int->these_Ints_overhere;
[/code]
And if we want the pointer value to enter into a function we'll do this
[code]
dont_mind_me_just_calling_my_function(&overHere_int);
[/code][/QUOTE]
If overHere_int is a pointer to some struct or something that has a member called these_Ints_overhere, yes.
And if overHere_int is not already a pointer, normally yes, since the unary operator & is generally used to get the address of something.
[editline]11th February 2011[/editline]
[QUOTE=Haley;27988576]oh yeah. cuz g() could be used outside of f... and that would leave room for errors[/QUOTE]
I don't see how this would create an error. If the value inside the function was a constant, then there is no technical barrier I think, but let's just leave it at "It's not possible according to the current C++ standard".
[QUOTE=Haley;27988576]if I wanted to pass the value in i'd have to do so with an argument or by putting it in a global variable, correct?[/QUOTE]
That or a variable in file-scope. People generally pass things around via parameter though.
[QUOTE=ZeekyHBomb;27988588]If overHere_int is a pointer to some struct or something that has a member called these_Ints_overhere, yes.
And if overHere_int is not already a pointer, normally yes, since the unary operator & is generally used to get the address of something.[/QUOTE]
Oh wait. i think i just confused you regarding what I meant.
Sorry.
overHere_int is suppose to be an address
so does this
[code]overHere_int->these_Ints_overhere;[/code]
make overHere_int equal the address of these_Ints_overhere
No.
The operator-> is generally used to access members of pointers, similar to how you use the operator ..
[cpp]struct Foo
{
int bar;
}
int main()
{
Foo foo;
foo.bar;
Foo *pFoo = &foo;
pFoo.bar; //compiler error
pFoo->bar; //accesses bar alike foo.bar
(*pFoo).bar; //the asterisk dereferences the pointer, so now you can use the operator .; this is actually what pFoo->bar does
}[/cpp]
[QUOTE=ZeekyHBomb;27988652]No.
The operator-> is generally used to access members of pointers, similar to how you use the operator ..
[cpp]struct Foo
{
int bar;
}
int main()
{
Foo foo;
foo.bar;
Foo *pFoo = &foo;
pFoo.bar; //compiler error
pFoo->bar; //accesses bar alike foo.bar
(*pFoo).bar; //the asterisk dereferences the pointer, so now you can use the operator .; this is actually what pFoo->bar does
}[/cpp][/QUOTE]
pFoo is a pointer then
To "dereference" is to get the actual struct,int,string or basically the real substance behind the pointer. correct?
[QUOTE=Haley;27988860]pFoo is a pointer then
To "dereference" is to get the actual struct,int,string or basically the real substance behind the pointer. correct?[/QUOTE]
Yes.
In his example, saying *pFoo is exactly the same as saying foo.
[QUOTE=Jallen;27988920]Yes.
In his example, saying *pFoo is exactly the same as saying foo.[/QUOTE]
Got it.
So what is the difference between and object and a struct?
oh... Objects can have member functions. structs can't.
I don't really see the benefit of that. Why no just have all your functions global? Oh, because you might want to call dance() on objects that dance differently.
I think I just answered my own question.
@_r4nk
I noticed you use "std::cout << a"
"<<" is for streams right?
What other kind of streams are there?
I guess different streams accept different variables?
I don't think an object is clearly defined for C++, though I'd use it as a synonym for a class or struct. And the only difference between those is the default visibility (private vs public).
What you might be thinking of is a [url=http://en.wikipedia.org/wiki/Plain_old_data_structure]POD[/url] type, which may not contain virtual functions (see polymorphism).
You might not want to have all your functions global, because functions may be designed to be used with certain classes.
[cpp]struct A
{
//this can be called via A a; a.doSomething();
void doSomething();
}
//A& is a reference to an A-object
//this can be called via A a; doSomething(a); and is IMO not as straight forward as a.doSomething();
void doSomething(A&);[/cpp]
<< is actually a binary left shift, but it's overloaded for std-streams. You can find various standard streams listed [url=http://www.cplusplus.com/reference/iostream/]here[/url].
[url=http://www.cplusplus.com/reference/iostream/ostream/operator%3C%3C/]These[/url] are the kind of stuff you can output via an std::ostream. In addition to that you can easily define your own rules, [url=http://www.cplusplus.com/reference/string/operator%3C%3C/]like it has been done for std::strings[/url].
[QUOTE=Haley;27989093]
So what is the difference between and object and a struct?
oh... Objects can have member functions. structs can't.
[/QUOTE]
Actually, structs can have member functions too; the only technical difference between a struct and a class in C++ is that members of structs are public by default, and members of classes are private by default.
By [i]convention[/i], though, structs are used in C++ the same way they are in C: as "dumb" data containers, rather than "smart" objects. So you typically don't put member functions in a struct. (It can be useful to add a constructor, though, to help with initializing variables when you create an instance of the struct.)
[QUOTE=Haley;27989093]
I don't really see the benefit of that. Why no just have all your functions global? Oh, because you might want to call dance() on objects that dance differently.
[/QUOTE]
It facilitates [url=http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming]polymorphism[/url] as you mentioned, and also associates functions with a class so that [url=http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)]encapsulation[/url] can be enforced by the compiler. (A private function can only be called by other functions in the same class; that can't be done with functions that aren't in any class.)
I'm not saying you should give up, but you really should read up on the basic syntax of the language before you throw yourself into it, or you'll have a hard time adjusting
I started at [url]www.cplusplus.com[/url], it's definitely a good place to get your basic syntax down, and it's a handy reference for things like stl containers, arguments for standard libraries etc.
You're learning backwards, I did this and got nowhere.
[url]http://www.e-booksdirectory.com/details.php?ebook=3516[/url]
This is the e-book I used. It is pretty long but it explains things really really well. I can say with certainty that if you read it you will understand everything it teaches, which is pretty much all the standard c++ junk you will run into.
Sorry, you need to Log In to post a reply to this thread.