Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Are functions in DBPro similar to classes in C++?

Author
Message
Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 7th Jul 2009 08:44
Just curious.

wickedly kick it
18
Years of Service
User Offline
Joined: 13th Jul 2006
Location: Fort-worth Texas
Posted: 7th Jul 2009 09:30
functions are similar to functions

Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 7th Jul 2009 09:31
o rlly? kthxbai.

But are they similar to C++ classes?

wickedly kick it
18
Years of Service
User Offline
Joined: 13th Jul 2006
Location: Fort-worth Texas
Posted: 7th Jul 2009 09:42
Not really, they are kinda sorta, but they are more used to execute code really with variables.

like if i make a function i call MakeObjectCube(id,size,x,y,z) it would look like this:


then i can call that function anywhere in my code as long as the function is at the bottom/after the main loop.

like so:
MakeObjectCube(1,15,0,25,15)

thats about it Types seem like classes to me, not sure.



with that code you can call/set data from that array like so:

and then make an object like so:


that makes 10 boxes according to their properties you set earlier.

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 7th Jul 2009 10:30 Edited at: 7th Jul 2009 10:57
There are no classes in DBP, which is kind of sad, for they could really be useful at times.

What you use are global variables and arrays, possibly of user defined types (which are pretty much like C++'s structs) and functions.

What you can however do to mimic object oriented programming is to set up objects as memory blocks (preferably using make memory, or better yet, IanM's alloc with corresponding peek and poke functions, over memblocks since you may only have 256 of these at once, I think).
Then each such "object pointer" would begin with a header of a set number of bytes describing the object (ie. public / private, static, number of fields and methods, and so on). You then set up your "method functions" like so:



As you can see, it gets rather messy and you should therefore probably write a precompiler (which works with statements such as class, endclass, new, delete, etc.) if you want to use this system.

Well, there's my five cents at least

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 8th Jul 2009 03:16
Yep, there is nothing in DBPro to compare classes too.

In C++ classes basically define objects (and an object can be anything it doesn't have to be a real object). You can then define functions and variables within a class for the object. In DBPro all functions are global and are can be applied to the entire program. However in C++ if you put a function in a class and then use that class for an object, the function is for that object (a function for one object can't work for another object). You could also have the same function in different classes do different things too.

I hope that helps you understand C++ classes.

Login to post a reply

Server time is: 2024-11-24 03:44:22
Your offset time is: 2024-11-24 03:44:22