Jump to content
  • Advertisement
Sign in to follow this  
Ancient Spirit

Interesting thought....

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I am having this thought... Can i combine a bunch of functions in a sort of an object, i mean under "C", and pure "C". Basically, translate this to "C":
class test {
public:
    test();
    void tester(int a);
private:
    int s;
};

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Function Pointers. Take a look at the Quake 3 source. Its done a lot of times, obviously you wont have inheritance and such, but you can cheat.



struct test
{
void (*test)();
void (*tester)(int a);

int s;
}




Also, my syntax may be wrong, I don't frequently use function pointers.

Share this post


Link to post
Share on other sites
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).

Share this post


Link to post
Share on other sites
Quote:
Original post by Catafriggm
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).


Or that...

Share this post


Link to post
Share on other sites
Quote:
Original post by Catafriggm
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).


Can you please explain a bit more...

Share this post


Link to post
Share on other sites
Quote:
Original post by Ancient Spirit
Quote:
Original post by Catafriggm
The way to do that is to have a series of global functions which act on a handle to the instance (either a pointer to a struct, or an opaque value).


Can you please explain a bit more...



struct test
{
int s;
}

void test_test(test& object)
{
s = 0;
return;
}

void test_tester(test& object, int a)
{
s = a; // ?
return;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Ancient Spirit
i dont think u can use the "&" in "C"


picky picky people, this is what I get for being a pure C++ programmer


struct test
{
int s;
};

void test_test(test* object)
{
object->s = 0;
return;
}

void test_tester(test* object, int a)
{
object->s = a; // ?
return;
}






And I fixed a bug aswell. Now fixed the real bug.

[Edited by - Richy2k on October 9, 2005 7:17:13 PM]

Share this post


Link to post
Share on other sites
No, you can't, but you can replace it by a pointer.

[edit] Fixed at time of writing.
[edit2] And don't forget to actually use the pointer... ->
void test_tester(test* object, int a)
{
object->s = a;
return;
}



jfl.

Share this post


Link to post
Share on other sites
Here are a couple of links that might help.

Object-Oriented C: Creating Foundation Classes Part 1
Object Oriented Programming in C
Object Oriented Programming in C

Here's a complete book on the subject: Object-Oriented Programming With ANSI-C (pdf)

If you want to get an idea of how vtables are constructed, if you have access to a Windows based compiler, open the iunknown.h in a text editor and examine what it does with structures, forward references, and function pointers. You might also have to search for macro definitions in other headers.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!