0

I'm doing a higher complex system for a company. I have the assignment to keep one loop for each (Draw, Update). However their system requires me to extend the base class for the different calculations; and there will be several extenders. What i did to test this was ->

struct base_line
{
    template<typename a> bool operator+=(a b){bs[0] = b;}
    virtual void foo(){}
    base_line *bs[2];
};

struct base : base_line
{
    virtual void foo(){
        printf("Nice\n");
    }
};

base_line bse;
base bser;

int _tmain(int argc, _TCHAR* argv[])
{
    bse+=bser;
    while(true)
    {
        if(bse.bs[0]){
            bse.bs[0]->foo();
        }
    }
    return 0;
}

however ofcourse you cannot convert from base to base_line *. Which basically ruins what i am trying to accomplish; The code previously shown is supposed to launch the virtual foo(); printing Nice\n. Does anyone know how i can accomplish this?

WhozCraig
  • 65,258
  • 11
  • 75
  • 141
  • The question is unclear. What are you really attempting here? Why can you not just pass a pointer to the `operator+=` instead of a value? – David Rodríguez - dribeas Aug 19 '13 at 15:50
  • I'd start with a reference (`base_line&`) for your operator parameter rather than a [object-sliced](http://stackoverflow.com/questions/274626/what-is-the-slicing-problem-in-c/274634#274634) value copy its currently receiving. From that, use `&b` for your pointer array assignment. For what you're doing a template isn't needed (and yours has an indeterminate return value since you defined it to return `bool` but have no `return` in the body. – WhozCraig Aug 19 '13 at 15:55
  • Oh why not think like that. This solves my problem also. Granted the question was bad. Thanks David. – SuperAgenten Johannes Schaeder Aug 19 '13 at 15:56

0 Answers0