Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:20:36+00:00 2026-06-07T22:20:36+00:00

I am using the example http://www.codeproject.com/Articles/3267/Implementing-a-Subject-Observer-pattern-with-templ to implement a templated subject/observer pattern. However, I

  • 0

I am using the example http://www.codeproject.com/Articles/3267/Implementing-a-Subject-Observer-pattern-with-templ to implement a templated subject/observer pattern. However, I am getting annoying compile errors looking like inheritance isn’t working, or an odd cast. Any help would be great. At the bottom of the post is the line causing the issue.

The error

FooManager.h: In member function
    'ReturnEnum FooManager::AddBar(BarPtr)':

Foo.h:150: error: no matching function for call to
    'Bar::attach(FooManagerPtr)'

Subject.h:23: note: candidates are: 
    void Subject<T>::attach(Observer<T>) [with T = boost::shared_ptr<Bar>]

The Code

types.h

class Bar;
typedef boost::shared_ptr<Bar> BarPtr;

class FooManager;
typedef boost::shared_ptr<FooManager> FooManagerPtr;

Observer.h

#include "types.h"
template <class T>
class Observer
{
    public:
        Observer(){}
        virtual ~Observer() {}
        virtual void update(T subject) = 0;
};

Subject.h

#include "types.h"
template <class T>
class Subject
{
    private:
        vector< Observer<T> > m_observers;

    public:
        Subject() {}
        virtual ~Subject() {}
        void attach(Observer<T> observer)
        {
            m_observers.push_back(observer);
        }

        void notify()
        {
            for(vector< Observer<T> >::iterator it = m_observers.begin(); it != m_observers.end(); ++it)
            {
                (*it)->update(static_cast<T>(this));
            }
        }
};

Bar.h

#include "types.h"
class Bar             : public Subject<BarPtr>
{
};

FooManager.h

#include "types.h"
class FooManager                : public Observer<BarPtr>
{
    public:
        ReturnEnum AddBar(BarPtr pBar)
        {
            pBar->attach( FooManagerPtr(this, boost_null_deleter()) );
        }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:20:37+00:00Added an answer on June 7, 2026 at 10:20 pm

    Depending on what you want to achieve, you could try to change (warning, untested code!):

        void attach(Observer<T> observer)
        {
            m_observers.push_back(observer);
        }
    

    to

        void attach(boost::shared_ptr<Observer<T>> observer)
        {
            m_observers.push_back(observer);
        }
    

    and

    vector< Observer<T> > m_observers;
    

    to

    vector< boost::shared_ptr<Observer<T> > > m_observers;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following this http://www.codeproject.com/Articles/10020/Using-managed-code-in-an-unmanaged-application The example consist of 3 binaries: C# code C++/CLI code
From this example http://www.senchafiddle.com/#dPZn0 This displays a first panel, then a second one... using
I'm using the W3 Schools example: http://www.w3schools.com/PHP/php_ajax_database.asp to display a table of database data
I am using these rules and conditions in .htaccess to turn these http://www.example.com/index.php/about/history http://www.example.com/about/history/index.php
I'm going to do a wpf application using MVVM(It based on http://www.codeproject.com/KB/WPF/MVVMQuickTutorial.aspx ). This
I'm using ASP .NET rewriteModule to rewrite http://example.com to http://www.example.com . <section name=rewriteModule type=RewriteModule.RewriteModuleSectionHandler,
Using Bill Burrows Intro to SL4 and WCF Ria Services - Golf Example (http://www.myvbprof.com/MainSite/index.aspx#/zSL4_RIA_01),
I'm using this example http://demos.flesler.com/jquery/scrollTo/ . I've managed to implement it but when my
Using an example from http://www.tizag.com/phpT/fileupload.php . I am using PHP 5.3 at godaddy I
Can you explain how mod_rewrite works using this as an example: http://www.domain.com/page.php?q=keyword1,keyword2,keywordn&page=x&param=i => http://www.domain.com/page/keyword1,keyword2,keywordn?page=x&param=i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.