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. 14 1697 ax****@gmail.com wrote:
int add(const MyClass *element) { return 1; }
does not have override
virtual int add(const Tip element) = 0;
when Tip is MyClass*.
If Tip is Myclass*, then const Tip is:
MyClass* const
hence the overrider would be
int add(MyClass* const element) { ..
Ron Natalie je napisao/la:
ax****@gmail.com wrote:
int add(const MyClass *element) { return 1; }
does not have override
virtual int add(const Tip element) = 0;
when Tip is MyClass*.
If Tip is Myclass*, then const Tip is:
MyClass* const
hence the overrider would be
int add(MyClass* const element) { ..
I tried changing the 'add' method to what you've said, but I'm still
getting the same error message. ax****@gmail.com wrote:
Hello again and thnx to everybody for previous feedbacks.
This code works quite nicely when I omit the inheritance in
MyContainer.h
---------------
MyClass.h
[snip]
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);
};
[snip]
-------------
main.cpp
-------------
#include <iostream>
#include "MyClass.h"
#include "MyContainer.h"
void main() {
MyClass myInstance;
MyContainer myContainerInstance;
}
[snip]
Ron Natalie has already answered your question. Two comments on your
code, though.
First, please don't put "#include namespace std" in a header file.
It's a bad habit and will come back to bite you - or one of your
colleagues - some day.
Second, don't use "void main" - it's not standard, and probably won't
work if you switch to a different compiler.
Best regards,
Tom
Thomas Tutone je napisao/la:
ax****@gmail.com wrote:
Hello again and thnx to everybody for previous feedbacks.
This code works quite nicely when I omit the inheritance in
MyContainer.h
---------------
MyClass.h
[snip]
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);
};
[snip]
-------------
main.cpp
-------------
#include <iostream>
#include "MyClass.h"
#include "MyContainer.h"
void main() {
MyClass myInstance;
MyContainer myContainerInstance;
}
[snip]
Ron Natalie has already answered your question. Two comments on your
code, though.
First, please don't put "#include namespace std" in a header file.
It's a bad habit and will come back to bite you - or one of your
colleagues - some day.
Second, don't use "void main" - it's not standard, and probably won't
work if you switch to a different compiler.
Best regards,
Tom
Thnx Tom, you're right, I shouldn't use void main, but I usually use
WinMain anyway. As for the using namespace directive, you're right,
I'll remove it.
If I understood correctly, Ron Natalie said that I should change
int add(const MyClass *element) { return 1; };
to:
int add(MyClass const *element) { return 1; };
I tried doing this, but with no effect.
axe...@gmail.com wrote:
Thnx Tom, you're right, I shouldn't use void main, but I usually use
WinMain anyway. As for the using namespace directive, you're right,
I'll remove it.
If I understood correctly, Ron Natalie said that I should change
int add(const MyClass *element) { return 1; };
to:
int add(MyClass const *element) { return 1; };
No, he said change it to:
int add(MyClass* const element) { return 1; }
(Lose that ";" after the closing bracket of the function definition, by
the way.)
Best regards,
Tom
I'm getting a different error message, though...
MyContainer.obj : error LNK2019: unresolved external symbol "public:
__thiscall BaseContainer<class MyClass *>::~BaseContainer<class MyClass
*>(void)" (??1?$BaseContainer@PAVMyClass@@@@QAE@XZ) referenced in
function __unwindfunclet$??0MyContainer@@QAE@XZ$0
MyContainer.obj : error LNK2019: unresolved external symbol "public:
__thiscall BaseContainer<class MyClass *>::BaseContainer<class MyClass
*>(void)" (??0?$BaseContainer@PAVMyClass@@@@QAE@XZ) referenced in
function "public: __thiscall MyContainer::MyContainer(void)"
(??0MyContainer@@QAE@XZ)
What does this mean? I provided definitions for the constructor and the
destructor in BaseContainer.cpp
ps Thomas: I changed it to what Ron said.
Strange, this reports the previous error message in the project I've
posted, but in my original project everything is working neatly.
Ron, Thomas - Thnx for your feedback
Bye ax****@gmail.com wrote:
I'm getting a different error message, though...
MyContainer.obj : error LNK2019: unresolved external symbol "public:
__thiscall BaseContainer<class MyClass *>::~BaseContainer<class MyClass
*>(void)" (??1?$BaseContainer@PAVMyClass@@@@QAE@XZ) referenced in
function __unwindfunclet$??0MyContainer@@QAE@XZ$0
MyContainer.obj : error LNK2019: unresolved external symbol "public:
__thiscall BaseContainer<class MyClass *>::BaseContainer<class MyClass
*>(void)" (??0?$BaseContainer@PAVMyClass@@@@QAE@XZ) referenced in
function "public: __thiscall MyContainer::MyContainer(void)"
(??0MyContainer@@QAE@XZ)
What does this mean?
It means you didn't provide definitions for the constructor and
destructor for template<class BaseContainer.
>I provided definitions for the constructor and the
destructor in BaseContainer.cpp
You didn't post BaseContainer.cpp, but the solution to your problem is
in the FAQ (sections 35.12 and following): http://www.parashift.com/c++-faq-lit...html#faq-35.12
Best regards,
Tom
Thomas Tutone je napisao/la:
ax****@gmail.com wrote:
I'm getting a different error message, though...
MyContainer.obj : error LNK2019: unresolved external symbol "public:
__thiscall BaseContainer<class MyClass *>::~BaseContainer<class MyClass
*>(void)" (??1?$BaseContainer@PAVMyClass@@@@QAE@XZ) referenced in
function __unwindfunclet$??0MyContainer@@QAE@XZ$0
MyContainer.obj : error LNK2019: unresolved external symbol "public:
__thiscall BaseContainer<class MyClass *>::BaseContainer<class MyClass
*>(void)" (??0?$BaseContainer@PAVMyClass@@@@QAE@XZ) referenced in
function "public: __thiscall MyContainer::MyContainer(void)"
(??0MyContainer@@QAE@XZ)
What does this mean?
It means you didn't provide definitions for the constructor and
destructor for template<class BaseContainer.
I provided definitions for the constructor and the
destructor in BaseContainer.cpp
You didn't post BaseContainer.cpp, but the solution to your problem is
in the FAQ (sections 35.12 and following):
http://www.parashift.com/c++-faq-lit...html#faq-35.12
Best regards,
Tom
Thnx! ax****@gmail.com wrote:
\
right, I shouldn't use void main, but I usually use
WinMain anyway. As for the using namespace directive, you're right,
I'll remove it.
If I understood correctly, Ron Natalie said that I should change
int add(const MyClass *element) { return 1; };
to:
int add(MyClass const *element) { return 1; };
I tried doing this, but with no effect.
No you don't understand me. The above two are IDENTICAL
and NOT what I wrote.
int addMyclass * const element)
is what I wrote and I meant it.
In article <44***********************@news.newshosting.com> , ro*@spamcop.net says...
[ ... ]
int addMyclass * const element)
is what I wrote and I meant it.
Well, I'm pretty sure what you meant (and wrote) was:
int add(Myclass * const element)
but what's a missing parenthesis between friends?
[I suppose the answer to that would depend on whether you classify the
compiler as a friend. :-) ]
--
Later,
Jerry.
The universe is a figment of its own imagination.
Ron Natalie je napisao/la:
ax****@gmail.com wrote:
\
right, I shouldn't use void main, but I usually use
WinMain anyway. As for the using namespace directive, you're right,
I'll remove it.
If I understood correctly, Ron Natalie said that I should change
int add(const MyClass *element) { return 1; };
to:
int add(MyClass const *element) { return 1; };
I tried doing this, but with no effect.
No you don't understand me. The above two are IDENTICAL
and NOT what I wrote.
int addMyclass * const element)
is what I wrote and I meant it.
Thnx, got it. It works now.
Thomas Tutone wrote:
ax****@gmail.com wrote:
>Hello again and thnx to everybody for previous feedbacks. This code works quite nicely when I omit the inheritance in MyContainer.h
--------------- MyClass.h
[snip]
>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);
};
[snip]
>------------- main.cpp -------------
#include <iostream>
#include "MyClass.h" #include "MyContainer.h"
void main() { MyClass myInstance; MyContainer myContainerInstance;
}
[snip]
Ron Natalie has already answered your question. Two comments on your
code, though.
First, please don't put "#include namespace std" in a header file.
It's a bad habit and will come back to bite you - or one of your
colleagues - some day.
Second, don't use "void main" - it's not standard, and probably won't
work if you switch to a different compiler.
Third, '#pragma once' is also not standard and should be guarded by
#ifdef's identifying your specific compiler (other compilers will need
the usual include guards of course). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Axel Straschil |
last post by:
Hello!
Im working with new (object) classes and normaly call init of ther
motherclass with callin super(...), workes fine.
No, I've got a case with multiple inherance and want to ask if this...
|
by: Graham Banks |
last post by:
Does using multiple inheritance introduce any more performance overhead than
single inheritance?
|
by: km |
last post by:
Hi all,
In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ?
thanks in...
|
by: Sebastian Böck |
last post by:
Hello all,
i have a view defined as a simple select of a table.
This table is inherited by a couple of others.
All entries belong to the child-tables.
I also have an unconditional update rule...
|
by: Kevin Newman |
last post by:
I have been playing around with a couple of ways to add inheritance to a
JavaScript singleton pattern. As far as I'm aware, using an anonymous
constructor to create a singleton does not allow any...
| |
by: Shawnk |
last post by:
Some Sr. colleges and I have had an on going discussion relative to when and
if
C# will ever support 'true' multiple inheritance.
Relevant to this, I wanted to query the C# community (the...
|
by: colint |
last post by:
Hi
I'm fairly new to c++ and I have a question regarding inheritance. I'm
trying to create a class based on 2 inherited classes, e.g.
class A
{
...
}
class B: public A
|
by: Jess |
last post by:
Hello,
I've been reading Effective C++ about multiple inheritance, but I
still have a few questions. Can someone give me some help please?
First, it is said that if virtual inheritance is...
|
by: raylopez99 |
last post by:
Well, contrary to the implication in my 2000 textbook on C# (public
beta version), C# does allow multiple inheritance, so long as it's
serially chained as follows:
class derived02 : derived01
{...
|
by: Rocketmagnet |
last post by:
Hi all,
I have been kind of forced (honestly) into writing a class structure
which contains a Diamond of Death, and I'm not entirely sure what to
do about it. This is a simplified version of my...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |