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.

Dark GDK / A quick question on classes...

Author
Message
Karxdurik
16
Years of Service
User Offline
Joined: 15th Jun 2008
Location:
Posted: 24th Aug 2008 02:30
I just started with Dark GDK and I've only learned the basics of c++. I'm sorry if this seems like an easy question or something. Okay, now if you make an object in your DarkGDK function and then call a function accessing that objects variables, will it work? I've been trying to get it to work, and I've had no luck. Here's an example of what I'm talking about.

Sorry about it not being indented or anything, I just typed it in quick in this message box. So is it possible to call object functions while in a different function than it was declared it?
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 24th Aug 2008 03:17
Watch your syntax.



Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Karxdurik
16
Years of Service
User Offline
Joined: 15th Jun 2008
Location:
Posted: 24th Aug 2008 03:38
Well that wasn't my actual code, just a quick example of the concept I have a question of that I typed out quickly in the little message box. I want to know whether or not you can use object functions, like the one in my example, "object.getvariable()", in another function that is called in the main loop function like DarkGDK. So basically, should that code work? Because whenever I run a program where I try to do that, it brings up an two errors that make it look like they don't recognize the object as existing.
Carlos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 24th Aug 2008 05:31
You can't use object inside the blafunction() since object is declared local in DarkGDK().
You can declare object as a global variable or you pass by reference or pointer as an argument in blafunction().
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 24th Aug 2008 08:40
class bla
{
int variable;

public:
void setvariable(int var)
{
variable = var;
}
int getvariable()
{
return variable;
}
};

void blafunction(bla paramObject)
{
int bla2 = paramObject.getvariable();
}

void DarkGDK(void)
{
bla object;

while(LookGDK())
{
blafunction(object);
}

return;
}

~you can call me lantz~
Karxdurik
16
Years of Service
User Offline
Joined: 15th Jun 2008
Location:
Posted: 24th Aug 2008 19:38
Thanks elantzb, that's exactly what I was wondering.

Login to post a reply

Server time is: 2024-09-30 05:21:28
Your offset time is: 2024-09-30 05:21:28