Send Toon-members mailing list submissions to
address@hidden
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.nongnu.org/mailman/listinfo/toon-members
or, via email, send a message with subject or body 'help' to
address@hidden
You can reach the person managing the list at
address@hidden
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Toon-members digest..."
Today's Topics:
1. NEW(with code) : Implementation of BaseClass with virtual
template functions with TOON (Gabriel N?tzi)
----------------------------------------------------------------------
Message: 1
Date: Fri, 19 Mar 2010 17:46:08 +0100
From: Gabriel N?tzi <address@hidden>
Subject: [Toon-members] NEW(with code) : Implementation of BaseClass
with virtual template functions with TOON
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset="us-ascii"
(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....)
like
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......
(SEE ATTACHED SIMPLE CODE!!)
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!!
=========================================CODE======================================================
#include <iostream>
#include <TooN/TooN.h>
using namespace std;
using namespace TooN;
template<int NDOF>
class DynamicSystem {
public:
DynamicSystem(){
};
~DynamicSystem(){
};
virtual Matrix<NDOF,NDOF> get_M(double t, Vector<NDOF> x)=0;
private:
int ndof;
};
class WoodPecker : public DynamicSystem<3>{
public:
WoodPecker(){
};
~WoodPecker(){
};
Matrix<3,3> get_M(double t, Vector<3> x){
Matrix<3,3> A =Identity;
return A;
}
};
template<int NDOF>
class Solver{
public:
Solver(DynamicSystem<NDOF> & myref): ref(myref) {
};
~Solver(){
};
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) :-)
}
};
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.gnu.org/pipermail/toon-members/attachments/20100319/5dfd8339/attachment.html
------------------------------
_______________________________________________
Toon-members mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/toon-members
End of Toon-members Digest, Vol 43, Issue 2
*******************************************