-
July 16th, 2015, 03:34 AM
#1
Inherit a class through smart pointer
hi,
I am seeing a declaration something like this,
Code:
class MyTest: public boost::shared_ptr<SomeTest>
{
};
I am not sure why is it not
Code:
class MyTest: public SomeTest
{
};
What is the reason for the smart pointer here, we normally inherit a class, but why we need to inherit from a pointer to a class!?
-
July 16th, 2015, 06:40 AM
#2
Re: Inherit a class through smart pointer
without knowing more about what this is and does.... hard to tell.
the above simply derives a class from a shared_ptr of SomeTest...
possibly because mytest needs to refer to "no test" or needs to be able to dynamically indirectly bind to different tests.
note that because deriving from the smart pointer, mytest does NOT inherit the members of SomeTest, it inherits the members of the smart pointer class.
-
July 17th, 2015, 02:35 PM
#3
Re: Inherit a class through smart pointer
Originally Posted by mce
I am seeing a declaration something like this,
Code:
class MyTest: public boost::shared_ptr<SomeTest>
{
};
This is more straightforward and probably what was wanted to be achieved.
Code:
typedef boost::shared_ptr<SomeTest> MyTest;
Last edited by tiliavirga; July 18th, 2015 at 06:57 AM.
-
July 21st, 2015, 04:04 AM
#4
Re: Inherit a class through smart pointer
Hi i got an error while i am building a dll library regarding the above:
Code:
class DLL_EXPORT MyTest: public boost::shared_ptr<SomeTest>
{
};
error C2562: 'boost::shared_ptr<T>:perator []' : 'void' function returning a value
if i remove the DLL_EXPORT, the compile error gone. How to solve this? I am exporting MyTest in a dll library.
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
|