'pass through member function'

Started by
9 comments, last by cozzie 9 years, 9 months ago

Hi,

I was wondering if there's s a clean way to do this:

- assume we have class A and B

- class B has a member 'SetThingie(const int pValue)'

- class A has a vector of class B

- class A has a 'current B' int

- class A has a member 'SetThingie(const int pValue)', same as class B

- when class A SetThingie is called, it should call SetThingie of the class B object in the vector, with index 'current B'

Now the most straigt forward you would be something like this:


class ClassA
{
public:
    void SetThingie(const int pValue);

private:
    int currentIndex;
    std::vector<ClassB> mObjects;
}

class ClassB
{
public:
    void SetThingie(const int pValue);
}

void ClassA::SetThingie(const int pValue)
{
    mObjects[currentIndex].SetIndex(pValue);
}

Do you think there are easier/ cleaner ways to do this?

What about intefacing the Effect with Shader?


class ShaderBase {
public:
    
    virtual void setWorldMatrix(MATRIX &matrix) = 0; //-- For interface class.
     void SetIndex(int &value);
     std::vector<ShaderBase> ShaderArray;
     int currentIndex;
private:

};

class Effect : public ShaderBase {
  public:
 
  void setWorldMatrix(MATRIX &matrix); //-- Because shader base has a function called setWorldMatrix(MATRIX &) you overwrite the virtual function in ShaderBase 
   
private:
}

Or are you talking about using inheritences in classes? I thought interfacing was what you're looking for because of the SetThingy thingy thing example.

Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX
Advertisement

Wow, seems that that are other ways to do this.

To be honest, I'm not sure if they're improving readability of the code, and in the end maybe the most straight forward way will be the way to go.

The last solution although also looks interesting, but I believe this will need moving around (const) ref's when just need to set a shader constant (For each constant). So for no I'll go for the straight forward option.

Thanks again for sketching the options

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement