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

Recommended Posts

Hi I'm making a 3D engine as a dll. To do so, I give in the SDK pure virtual functions as below :
//file iTexture.h
class iTexture
{
public:
iTexture()				{};
virtual ~iTexture(void) {};

virtual	int	GetHeight(void) = 0;
virtual	int	GetWidth(void) = 0;

/* .... */
};


And inside my dll, I do this :
//file cTexture.h
#include "iTexture.h"

class cTexture : public iTexture
{
friend	class	cTextureManager;

public:
cTexture(void);
virtual	~cTexture(void);

int	GetHeight(void);
int	GetWidth(void);

/* .... */
}


Problemes arises in derivated classes when I try to do something like that :
// file iStreamTexture.h

#include "iTexture.h"

class iStreamTexture : public iTexture
{
public:
iStreamTexture()	{};
~iStreamTexture()	{};

virtual	bool	LoadAVIStream(const char *filename) = 0;
/* ... */

}

// file cStreamTexture.h

#include "iStreamTexture.h"
#include "cTexture.h"

class cStreamTexture : public cTexture, iStreamTexture
{
public:
cStreamTexture();
virtual	~cStreamTexture();

/* ... */
}


Error C2259 happen (Unable to instanciate abstract classes). In a previous thread, Enigma gave me a solution to work around my problem. I want to know if it's the good solution to do such ? Let's look at other "dll engine" does as I do and they don't have this problem. Where am I wrong ?

Share on other sites
Make sure derived class has implementation of all pure virtual methods.

Share on other sites
Relying on interface is certainly a good thing, doing multiple inheritance is bad, very very bad :).

Your having a deadly diamond problem right now. You are trying to inherit from cTexture and IStreamTexture, both of which are depending on ITexture. I would recommand changing this and pulling that diamond out.

I think you can fix it if you try

using iStreamTexture::GetHeight;
using iStreamTexture::GetWidth;

in you cStreamTexture.

But this isn't the best solution. Also if you are working with dlls, you will need to export either your class (might not be in your best interest since you are working with interfaces anyway), or create a factory that will return you your interfaces. That factory will need to be exported (can be as simple as a CreateStreamTexture exported function).

Hope this helps,

Share on other sites
Quote:
 Original post by ShadxYour having a deadly diamond problem right now. You are trying to inherit from cTexture and IStreamTexture, both of which are depending on ITexture. I would recommand changing this and pulling that diamond out. I think you can fix it if you tryusing iStreamTexture::GetHeight;using iStreamTexture::GetWidth;in you cStreamTexture.

Here's what did :
	int	GetHeight(void)	{return cTexture::GetHeight();};	int	GetWidth(void)	{return cTexture::GetWidth();};

Quote:
 But this isn't the best solution. Also if you are working with dlls, you will need to export either your class (might not be in your best interest since you are working with interfaces anyway), or create a factory that will return you your interfaces. That factory will need to be exported (can be as simple as a CreateStreamTexture exported function).

I use a cTextureManager::CreateTexture(....) class inside the dll :)
As You said I have to get ride of this diamond problem...

Share on other sites
The problem is your use of non-virtual inheritance. With non-virtual inheritance a base class can be included multiple times in an inheritance hierarchy. For example your cStreamTexture inheritance hierarchy looks like:
    cStreamTexture      |        |      V        VcTexture     iStreamTexture    |               |    V               ViTexture       iTexture

Now cStreamTexture inherits two copies of iTexture. cTexture correctly overrides the pure virtual functions of one of those instances, but the pure virtual functions of the other instance are never overriden, causing cStreamTexture to be an abstract class.
By using virtual inheritance you resolve this problem and your inheritance hierarchy now looks like:
   cStreamTexture     |        |     V        VcTexture    iStreamTexture      |      |      V      V      iTexture

You now only have one copy of iTexture and cTexture overrides the pure virtual functions contained within.

This is actually one of the (relatively) few cases where multiple inheritance is probably a good solution to a problem. I certainly don't know of any nice equivalent solutions without using multiple inheritance.

It is important to note that this is a simple case of multiple inheritance. Since iTexture and iStreamTexture are abstract base classes many of the problems with general multiple inheritance cannot arise. In fact this form of virtual inheritance is so safe even Java implements it, via interfaces (no offense to Java programmers [lol]).

Enigma

Share on other sites
Enigma, you are my hero one more time :)
I found a "work around", but your solution is nice too.

many thx !

• 12
• 10
• 11
• 18
• 13
• Similar Content

• Hi fellow game devs,
First, I would like to apologize for the wall of text.
As you may notice I have been digging in vehicle simulation for some times now through my clutch question posts. And thanks to the generous help of you guys, especially @CombatWombat I have finished my clutch model (Really CombatWombat you deserve much more than a post upvote, I would buy you a drink if I could ha ha).
Now the final piece in my vehicle physic model is the differential. For now I have an open-differential model working quite well by just outputting torque 50-50 to left and right wheel. Now I would like to implement a Limited Slip Differential. I have very limited knowledge about LSD, and what I know about LSD is through readings on racer.nl documentation, watching Youtube videos, and playing around with games like Assetto Corsa and Project Cars. So this is what I understand so far:
- The LSD acts like an open-diff when there is no torque from engine applied to the input shaft of the diff. However, in clutch-type LSD there is still an amount of binding between the left and right wheel due to preload spring.
- When there is torque to the input shaft (on power and off power in 2 ways LSD), in ramp LSD, the ramp will push the clutch patch together, creating binding force. The amount of binding force depends on the amount of clutch patch and ramp angle, so the diff will not completely locked up and there is still difference in wheel speed between left and right wheel, but when the locking force is enough the diff will lock.
- There also something I'm not sure is the amount of torque ratio based on road resistance torque (rolling resistance I guess)., but since I cannot extract rolling resistance from the tire model I'm using (Unity wheelCollider), I think I would not use this approach. Instead I'm going to use the speed difference in left and right wheel, similar to torsen diff. Below is my rough model with the clutch type LSD:
speedDiff = leftWheelSpeed - rightWheelSpeed; //torque to differential input shaft. //first treat the diff as an open diff with equal torque to both wheels inputTorque = gearBoxTorque * 0.5f; //then modify torque to each wheel based on wheel speed difference //the difference in torque depends on speed difference, throttleInput (on/off power) //amount of locking force wanted at different amount of speed difference, //and preload force //torque to left wheel leftWheelTorque = inputTorque - (speedDiff * preLoadForce + lockingForce * throttleInput); //torque to right wheel rightWheelTorque = inputTorque + (speedDiff * preLoadForce + lockingForce * throttleInput); I'm putting throttle input in because from what I've read the amount of locking also depends on the amount of throttle input (harder throttle -> higher  torque input -> stronger locking). The model is nowhere near good, so please jump in and correct me.
Also I have a few questions:
- In torsen/geared LSD, is it correct that the diff actually never lock but only split torque based on bias ratio, which also based on speed difference between wheels? And does the bias only happen when the speed difference reaches the ratio (say 2:1 or 3:1) and below that it will act like an open diff, which basically like an open diff with an if statement to switch state?
- Is it correct that the amount of locking force in clutch LSD depends on amount of input torque? If so, what is the threshold of the input torque to "activate" the diff (start splitting torque)? How can I get the amount of torque bias ratio (in wheelTorque = inputTorque * biasRatio) based on the speed difference or rolling resistance at wheel?
- Is the speed at the input shaft of the diff always equals to the average speed of 2 wheels ie (left + right) / 2?
• By Estra
Memory Trees is a PC game and Life+Farming simulation game. Harvest Moon and Rune Factory , the game will be quite big. I believe that this will take a long time to finish
Looking for
Programmer
1 experience using Unity/C++
2 have a portfolio of Programmer
3 like RPG game ( Rune rune factory / zelda series / FF series )
4 Have responsibility + Time Management
and friendly easy working with others Programmer willing to use Skype for communication with team please E-mail me if you're interested
Split %: Revenue share. We can discuss. Fully Funded servers and contents
and friendly easy working with others willing to use Skype for communication with team please E-mail me if you're interested
we can talk more detail in Estherfanworld@gmail.com Don't comment here
Thank you so much for reading
Memory Trees : forget me not

Thank you so much for reading
Ps.Please make sure that you have unity skill and Have responsibility + Time Management,
because If not it will waste time not one but both of us

• We've now started desinging the 3rd level of "Something Ate My Alien".
This world is a gas planet, and all sorts of mayhem will be getting in our aliens way!
#screenshotsaturday

• Kepuh's Island is Multiplayer 3D Survival Game where you survive on the Kepuh's Islands, confronting challenges that are not only other players but also bosses, and even the environment itself.
We have a lowpoly faster battle-royale idea, where about 12 players on the map fighting for survival! Also adding some more things into that style such as bosses around the map giving you abilities and much more such as vehicles, weapons, skins, etc...
Now we are on cartase which is a crowdfunding online which purpose is to raise funds for the development of the game. Come and be part of this development.