CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2002
    Posts
    788

    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!?

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  3. #3
    Join Date
    Jun 2015
    Posts
    208

    Re: Inherit a class through smart pointer

    Quote Originally Posted by mce View Post
    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.

  4. #4
    Join Date
    Jul 2002
    Posts
    788

    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
  •  





Click Here to Expand Forum to Full Width

Featured