[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] NEW(with code) : Implementation of BaseClass with virtual

From: Gabriel Nützi
Subject: [Toon-members] NEW(with code) : Implementation of BaseClass with virtual template functions with TOON
Date: Fri, 19 Mar 2010 17:46:08 +0100

(Here again because source code was missing)

Hello all,

I have a basic question where I am completely stuck with TooN:
I dont know how to realize this:

I have a DynamicSystem Class which describes a Dynamical System with template parameter <int NDOF>
I would like to have a Class Solver which has a reference to an instance of DynamicSystem.
The solver should be able to call several virtual functions from DynamicSystem. (subClass could be a Ball or a Car or what ever :-))
The main problem is that this main functions take Vectors/Matrices as Input and give Vector and Matrices as Output back (depending on NDOF)
but when I want to properly define such a function in TOON i need templates (to be able to input also slices and so on....)


template<typename BaseM, typename BaseV>
Matrix<3,3,double,BaseM> get_M (double t, Vector<3,double, BaseV > x   ){
// some code

But the problem is that in C++ we can not define templates as virtual functions......

HOW DO I SOLVE this Problem with TooN?
How should I structure my Classes? Would be very helpful if someone can quickly append the changes in the attached source code (ITS SIMPLE :-))!

Thank you very much for your HELP!!


#include <iostream>
#include <TooN/TooN.h>

using namespace std;
using namespace TooN;

template<int NDOF>
class DynamicSystem {
virtual Matrix<NDOF,NDOF> get_M(double t, Vector<NDOF> x)=0;

int ndof;

class WoodPecker : public DynamicSystem<3>{

Matrix<3,3> get_M(double t, Vector<3> x){
Matrix<3,3> A =Identity;
return A;

template<int NDOF>
class Solver{
Solver(DynamicSystem<NDOF> & myref): ref(myref) {
DynamicSystem<NDOF> & ref;
void dosome(){
Vector<> a(NDOF);
cout << ref.get_M(0,a) <<endl; //works
// cout << ref.get_M(0,a.slice<>(1,NDOF)) <<endl; // does not work..... (shit) :-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]