A
axel22
Hello again and thnx to everybody for previous feedbacks.
This code works quite nicely when I omit the inheritance in
MyContainer.h
---------------
MyClass.h
---------------
#pragma once
#include "MyContainer.h"
class MyClass {
private:
int myInteger;
MyContainer memberContainer;
public:
MyClass(void);
~MyClass(void);
};
---------------------
MyContainer.h
---------------------
#pragma once
#include <vector>
using namespace std;
class MyClass; // forward declaration
class MyContainer : BaseContainer<MyClass *> {
private:
vector<MyClass *> myVector;
MyClass *pointer;
public:
MyContainer(void);
int add(const MyClass *element) { return 1; }
~MyContainer(void);
};
------------------------
BaseContainer.h
------------------------
#pragma once
template <class Tip>
class BaseContainer
{
public:
BaseContainer(void);
virtual int add(const Tip element) = 0;
~BaseContainer(void);
};
-------------
main.cpp
-------------
#include <iostream>
#include "MyClass.h"
#include "MyContainer.h"
void main() {
MyClass myInstance;
MyContainer myContainerInstance;
}
However, with BaseContainer inherited to MyContainer, the following
problem occurs:
f:\C++\Projects\Probarka\MyClass.h(9) : error C2259: 'MyContainer' :
cannot instantiate abstract class
due to following members:
'int BaseContainer<Tip>::add(const Tip)' : pure virtual
function was not defined
with
[
Tip=MyClass *
]
f:\C++\Projects\Probarka\BaseContainer.h(8) : see declaration
of 'BaseContainer<Tip>::add'
with
[
Tip=MyClass *
]
I can't understand what's wrong. Without the inheritance it works
perfectly. Please help.
This code works quite nicely when I omit the inheritance in
MyContainer.h
---------------
MyClass.h
---------------
#pragma once
#include "MyContainer.h"
class MyClass {
private:
int myInteger;
MyContainer memberContainer;
public:
MyClass(void);
~MyClass(void);
};
---------------------
MyContainer.h
---------------------
#pragma once
#include <vector>
using namespace std;
class MyClass; // forward declaration
class MyContainer : BaseContainer<MyClass *> {
private:
vector<MyClass *> myVector;
MyClass *pointer;
public:
MyContainer(void);
int add(const MyClass *element) { return 1; }
~MyContainer(void);
};
------------------------
BaseContainer.h
------------------------
#pragma once
template <class Tip>
class BaseContainer
{
public:
BaseContainer(void);
virtual int add(const Tip element) = 0;
~BaseContainer(void);
};
-------------
main.cpp
-------------
#include <iostream>
#include "MyClass.h"
#include "MyContainer.h"
void main() {
MyClass myInstance;
MyContainer myContainerInstance;
}
However, with BaseContainer inherited to MyContainer, the following
problem occurs:
f:\C++\Projects\Probarka\MyClass.h(9) : error C2259: 'MyContainer' :
cannot instantiate abstract class
due to following members:
'int BaseContainer<Tip>::add(const Tip)' : pure virtual
function was not defined
with
[
Tip=MyClass *
]
f:\C++\Projects\Probarka\BaseContainer.h(8) : see declaration
of 'BaseContainer<Tip>::add'
with
[
Tip=MyClass *
]
I can't understand what's wrong. Without the inheritance it works
perfectly. Please help.