|
-
November 10th, 2010, 02:46 AM
#1
c++ no virtual function found on table
Hello
i'm trying to create a vector list using the STL lib.
the first method works but the second crashes cause: virtual function _Build () not found on table.
What's wrong?
Compiled with gcc.
code:
//// Main
#include <iostream>
#include "TOcc.h"
#include "TColl.h"
#include <vector>
using namespace std;
int main()
{
DBE dbe;
cout << endl << " Method 1. it work!" << endl;
vector<_TOccV<DBE> *> list;
_TOccV<DBE> *p;
TOcc1 s1;
p = &s1;
list.push_back(p);
TOcc2 s2;
p = &s2;
list.push_back(p);
list[0]->Build ();
list[1]->Build ();
cout << endl << " Method 2. Don't work" << endl;
TColl list2;
list2.BuildAll ();
return 0;
}
codice:
///// TOcc.h
#ifndef TOCC_H_INCLUDED
#define TOCC_H_INCLUDED
#include<assert.h>
#include<vector>
using namespace std;
class DBE {
vector<int> someData;
public:
DBE () {};
};
template <typename S>
class _TOccV {
vector< vector<int> > *_data;
int _dataYSize;
virtual void _Build (void) { cout << endl << "_TOccV::_Build" << endl; };
public:
_TOccV () : _dataYSize(0) { };
_TOccV (int dataYSize) : _dataYSize(dataYSize)
{ _data = new vector< vector<int> >(dataYSize); };
~_TOccV ()
{ delete _data; _data = NULL; };
void Push (vector<int> *v, int where) { _data[where].push_back(*v); };
vector<int> Pop (int what) { assert(what < _data->size()); return (*_data)[what]; };
void Build (void) { _Build (); };
};
class TOcc1 : public _TOccV<DBE> {
void _Build (void) { cout << endl << "TOcc1::_Build" << endl; };
public:
TOcc1 () : _TOccV<DBE> (1) {};
};
class TOcc2 : public _TOccV<DBE> {
void _Build (void) { cout << endl << "TOcc2::_Build" << endl; };
public:
TOcc2 () : _TOccV<DBE> (1) {};
};
#endif // TOCC_H_INCLUDED
/////// TColl.h
#ifndef TCOLL_H_INCLUDED
#define TCOLL_H_INCLUDED
#include <vector>
#include "TOcc.h"
using namespace std;
class TColl {
vector<_TOccV<DBE> *> _list;
public :
TColl ();
void BuildAll (void);
};
TColl::TColl ()
{
_TOccV<DBE> *p;
TOcc1 s1;
p = &s1;
_list.push_back(p);
TOcc2 s2;
p = &s2;
_list.push_back(p);
};
void TColl::BuildAll (void)
{
unsigned int idx;
_TOccV<DBE> *p;
for (idx = 0; idx < _list.size(); idx++)
{
p = _list[idx];
p->Build ();
}
}
#endif // TCOLL_H_INCLUDED
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|