Hi, i´m doing a image/video processing library and i wanted to do a cascade style acquisition, processing and displaying. More or less like the following:
Code:
VideoNode<VideoSource> source("/dev/video0");
source.connect(VideoNode<BlurEffect>);
source.connect(VideoNode<OutputToWindow>);
source.connect(VideoNode<EdgeDetector>);
source.connect(VideoNode<OutputToFile>);
And i wanted to use templates instead of abstract classes to don´t suffer it´s overheads (virtual function call). So i
came up with the following code:
Code:
template<class T>
class VideoObject
{
public:
VideoObject() : object()
{
this->child = NULL;
};
void connect(VideoObject& child)
{
this->child = child;
}
private:
T object;
VideoObject child;
void nextFrame(unsigned char** buffer)
{
object->nextFrame(buffer);
if (child != NULL)
{
child->nextFrame(buffer);
}
}
};
But it seems that something is pretty wrong... The compiler gave me the following output:
Code:
1>c:\felipe\scarvideo\scarvideo\VideoObject.h(29) : error C2460: 'VideoObject<T>::child' : uses 'VideoObject<T>',
which is being defined
1> with
1> [
1> T=Source
1> ]
1> .\main.cpp(40) : see reference to class template instantiation 'VideoObject<T>' being compiled
1> with
1> [
1> T=Source
1> ]
1>c:\felipe\scarvideo\scarvideo\VideoObject.h(29) : error C2460: 'VideoObject<T>::child' : uses 'VideoObject<T>',
which is being defined
1> with
1> [
1> T=Etc
1> ]
1> .\main.cpp(41) : see reference to class template instantiation 'VideoObject<T>' being compiled
1> with
1> [
1> T=Etc
1> ]
1>.\main.cpp(43) : error C2664: 'VideoObject<T>::connect' : cannot convert parameter 1 from 'VideoObject<T>' to 'VideoObject<T> &'
1> with
1> [
1> T=Source
1> ]
1> and
1> [
1> T=Etc
1> ]
1> and
1> [
1> T=Source
1> ]
And this is the test code:
Code:
#include "VideoObject.h"
#include <iostream>
using namespace std;
class Source
{
public:
Source()
{
this->name = "source";
}
void nextFrame(unsigned char** buffer)
{
*buffer = new unsigned char[3];
strcpy((char*)*buffer, "ls");
}
private:
string name;
};
class Etc
{
public:
Etc()
{
name = "etc";
}
void nextFrame(unsigned char** buffer)
{
cout << "name: "<<name.c_str()<<"\nbuffer: "<<buffer<<"\n";
}
private:
string name;
};
int main()
{
VideoObject<Source> parent;
VideoObject<Etc> child;
parent.connect(child);
}
What could i do?
Ah, and yes, all filters, outputs and sources implement the nextFrame function in order to work with the VideoObject class.
Felipe.