SDL_Surface* SurfaceMattz said:for me it's:
CODE
Ranma13 said:I'm interested in doing some Pandora developing but I want to check out the device first before I start anything. I've currently done some Java and C# programming, but since both are reference-based, I'm a bit rusty when it comes to explicitly separating objects and pointers.
I'm actually making a game myself in Scala (which compiles to Java bytecode, so I could do it in Java), with lwjgl and jBullet. It's not a problem if you want to use Java on the Pandora; it works. I'll open-source my code when I've got it a little more structured, if you need inspiration (but my Scala code can become pretty unreadable at times )
Not to mention that I already said what you said in your post, in this thread :/'dflemstr' said:EDIT: there was a whole thread about this a while ago, search the forums.
Exophase said:Not to mention that I already said what you said in your post, in this thread :/
Hmm, oops...
I should pay more attention when posting, and read through the thread first, eh?
'lulzfish' said:Since it's a pointer, it doesn't make any sense to say, "optimizedImage.format" because optimizedImage is just a number.
Actually, it does make sense. A pointer is just a pointer(usually a 32bit integer) - it has no methods or other data contained within, so logically anything accessed with a '.' would be from the object it's pointing to.
Java made this leap, and simplified "->" into "." as do most (all?) scripting languages.
But I've learned that in C/C++, if they can use more symbols rather than less, they do. That's my only beef with the language.
Kramy said:But I've learned that in C/C++, if they can use more symbols rather than less, they do. That's my only beef with the language.
C isn't constructed in a way that 'makes sense' to us humans, but in a way that makes sense to the CPU. In machine code, "->" and "." are two very different operations(the first is usually 2 operations, actually). If C would have simplified "->" into "." as you say, then what happens when you don't have a pointer, but you have a variable that IS the object/struct itself? How would you access it's members then? etc...
I watched a great video about all this once, I think it was from Stanford somewhere on this youtube playlist:
CODE
http://www.youtube.com/view_play_list?p=FE6E58F856038C69
...and that link is a very good source for learning C++ by the way, so you have nothing to lose following it anyways (it's free university lectures! Online tutorials can't become better than this )
Hm and btw don't treat me like I know alot about C/C++, those languages are not my 'primary' languages; I focus more on Java/Scala at the moment.
EDIT: Spelling fixes. I should really sleep now.
the compiler can look at the type of the object and put in the correct machine code instruction equivalent, of course. Or you could have all objects as references, like most sensible languages.'dflemstr' said:then what happens when you don't have a pointer, but you have a variable that IS the object/struct itself? How would you access it's members then? etc...
'bencoder' said:the compiler can look at the type of the object and put in the correct machine code instruction equivalent, of course. Or you could have all objects as references, like most sensible languages.'dflemstr' said:then what happens when you don't have a pointer, but you have a variable that IS the object/struct itself? How would you access it's members then? etc...
All objects as references means all objects are heap allocated, which doesn't fit with C/C++'s memory allocation model.
Exophase said:All objects as references means all objects are heap allocated, which doesn't fit with C/C++'s memory allocation model.'bencoder' said:the compiler can look at the type of the object and put in the correct machine code instruction equivalent, of course. Or you could have all objects as references, like most sensible languages.
@bencoder And if the compiler would 'hide' the difference between reference variables and direct access variables behind the scenes, then you lose some control over the memory management that is needed sometimes in C. Remember: In C++, there's no real difference between an int and, say, a class with 4 byte-sized members. To the compiler, a pointer is just yet another number; everything is just a stack of bytes. C++ is very down-to-the-hardware, and simplifications like you describe them would not be possible.
Now you have setup the operator you can easily add this Vector to another one:'Mithrildor' said:Can anyone explain me what Operator Overloading is? Im stuck in a tutorial because I dont know what Operator Overloading is and I cant get the hang of how the tutorial explains it to me, now after google searches I still dont get it.
It's basically providing your own functions for standard operators (+, -, /,*,+=)
When you are writing a class, you might want to tell the compiler how it might go about adding two of your class objects together. For argument's sake we'll say this is a vector class...
CODE
MyClass MyClass:perator+(MyClass c)
{
x += c.x;
y += c.y;
z += c.z;
return *this;
}
That's not a good example for operator overloading, though, because it doesn't do what the user expects from an operator+.'PokeParadox' said:CODE
MyClass MyClass:perator+(MyClass c)
{
x += c.x;
y += c.y;
z += c.z;
return *this;
}
Yeah, it modifies the original class... So avoid that particular code. Everyone got the idea, though, most probably.Xmas said:That's not a good example for operator overloading, though, because it doesn't do what the user expects from an operator+.
'Xmas' said:That's not a good example for operator overloading, though, because it doesn't do what the user expects from an operator+.'PokeParadox' said:CODE
MyClass MyClass:perator+(MyClass c)
{
x += c.x;
y += c.y;
z += c.z;
return *this;
}
Yeah... wasn't well thought out, was just very quick to give an idea.
'dflemstr' said:@bencoder And if the compiler would 'hide' the difference between reference variables and direct access variables behind the scenes, then you lose some control over the memory management that is needed sometimes in C. Remember: In C++, there's no real difference between an int and, say, a class with 4 byte-sized members. To the compiler, a pointer is just yet another number; everything is just a stack of bytes. C++ is very down-to-the-hardware, and simplifications like you describe them would not be possible.
How would you lose control? It could transparently support both.
This isn't the most complex thing for a compiler to figure out. It's more than doable to check if something is a pointer and replace a period with a '->'
C/C++ favour complexity to humans when there's no valid reason for it, because a compiler/computer can figure it out just fine. I write it off to the choices of C/C++'s creators.
I'll check out those Youtube vids.