C++ OOP library and Interface

Just starting out? Need help? Post your questions and find answers here.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: C++ OOP library and Interface

Post by Shield »

If you declare your destructor as virtual, it will still get added to the virtual table (hence the name of the keyword).

The warning message you got has to do with inheritance. You only need a virtual destructor in this case:

Code: Select all

// Given class Bar : public Foo
Bar* bar = new Bar();
Foo* foo = bar;
delete foo; // If you do this, the destructor of Bar will not be called.
Since PB doesn't do OOP, this isn't really a problem. You'd have to do something like this to cause the issue:

Code: Select all

*bar = NewBar()
DeleteFoo(*bar) // If you do this in PB, you've got bigger issues anyway.

Not sure if all that information matters to you, but I just wanted to point out some possible caveats. :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: C++ OOP library and Interface

Post by StarBootics »

I understand your point, but my point is this ;

The library I going to use is OpenCASCADE and the problem is I can't remove the Virtual Destructor from any class because C++ programmer using the same library might need them. Much worse according to the library license, if the code is being modified it should be returned. I don't think they will be very please about destructor disappearance from the code just to please me and PureBasic.

But asking to add two plain C function per class like these :

Code: Select all

extern "C" 
{ 
	
	Time* CreateTimeInterface() 
	{ 
		return new Time; 
	} 
	 
	int DeleteTimeInterface(const Time * ToBeDeleted) 
	{ 
		delete ToBeDeleted; 
		return 0; 
	} 
	 
}
will not matter C++ programmer at all because they will not use them anyway.

And I'm well aware about the fact that PureBasic doesn't do OOP and the virtual Destructor() is not used at all from PB. The main question is :

We are wasting memory for a not needed function into the interface, but it is so BAD ?

I have a working code, I'm happy !

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: C++ OOP library and Interface

Post by Shield »

Not sure what (parts) exactly you are using, but apparently OpenCascade is published
under LGPL which just requires you to publish any modifications you do under the same license,
so no problem there (publish here means that you have to make the code available on your server or wherever you want).

The problem isn't so much the memory usage but rather possible problems with interface itself (i.e. memory layout etc.).
What I don't quite get, though, is why you are trying to map an interface (i.e. "OOP") just to put the code into a procedural
module again, effectively calling a singleton instance via global variable.

If this is what you want to do with the classes provided by OpenCascade, why don't you just implement these wrapper-functions
in C++ and expose them directly, just like you exposed your NewTime() function? That way it will just work, regardless of
what compiler or platform you're using.
I have a working code, I'm happy !
Well great then, so put it to good use! :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: C++ OOP library and Interface

Post by StarBootics »

Shield wrote:The problem isn't so much the memory usage but rather possible problems with interface itself (i.e. memory layout etc.).
What I don't quite get, though, is why you are trying to map an interface (i.e. "OOP") just to put the code into a procedural
module again, effectively calling a singleton instance via global variable.
Because it's possible to drive a C++ class into PureBasic directly. And yes in this example it's a singleton instance via global variable but what is preventing me to use an Array, a Linked list or even a Map to store them and retrieving them by index or by a given name ? Nothing ...
Shield wrote:If this is what you want to do with the classes provided by OpenCascade, why don't you just implement these wrapper-functions
in C++ and expose them directly, just like you exposed your NewTime() function? That way it will just work, regardless of
what compiler or platform you're using.
Because this represent a lot of work in comparison of just adding two function per class and making sure that all methods are virtual. And the development is for Linux only and by the time I will have something working will take some years.

Take a look at FreeCAD if you want to see an example about what can be done.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: C++ OOP library and Interface

Post by StarBootics »

Hello everyone,

I'm continuing my tests before going to a more bigger challenge. I have added a "Date" class with a private function to my example just to see if work and it does.

The files are here : https://www.dropbox.com/s/loxgf4x5z8u2f ... 3.zip?dl=0

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: C++ OOP library and Interface

Post by StarBootics »

Hello everyone,

This is a newer version of this my example with C++ Classes and PureBasic. In this version I'm playing with structure to retrieve the version and using a structure to pass information to C++ class member.
https://www.dropbox.com/s/qkvy3lhqscfxd ... 4.zip?dl=0

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5526
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: C++ OOP library and Interface

Post by Kwai chang caine »

Apparently, that works here W7 v5.40 X86
V1.2.3
V1.2.3
197121
V1.2.3
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: C++ OOP library and Interface

Post by StarBootics »

Kwai chang caine wrote:Apparently, that works here W7 v5.40 X86
V1.2.3
V1.2.3
197121
V1.2.3
Thanks for sharing 8)
Which example did you try ?

The debugger output for "C++ Class Interface Example 00.pb" should look like :
LibTime V1.2.3
Time V1.0.1
Date V1.0.0
21:06:30 04-10-2016
23:52:45 04-10-2016
00:00:00 00-00-0000
23:23:23 15-10-2016
23
23
23
15
10
2016
The Time & Date Objects are invalid !
and for "C++ Class Interface Example 01.pb" it should look like :
15:09:55 25-10-2015
17:59:08 29-10-2016
Time Version : V1.0.1
Date Version : V1.0.0
LibTime Version : V1.2.3
MyTime no longer exist
MyDate no longer exist
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5526
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: C++ OOP library and Interface

Post by Kwai chang caine »

Excuse me :oops:
I'm under windows and only one code is for windows, I have test "Version Module" :wink:
ImageThe happiness is a road...
Not a destination
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: C++ OOP library and Interface

Post by StarBootics »

Kwai chang caine wrote:Excuse me :oops:
I'm under windows and only one code is for windows, I have test "Version Module" :wink:
This module is cross platform (Windows-Linux-MacOS) 32/64 bits. But this is not the main topic here.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Post Reply