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 6677105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:04:34+00:00 2026-05-26T04:04:34+00:00

I have a class defined in a header like so (abbreviated): class CairoRenderer {

  • 0

I have a class defined in a header like so (abbreviated):

class CairoRenderer
{
public:
    CairoRenderer();
    ~CairoRenderer();
...
protected:
    cairo_t* m_context;
    cairo_surface_t* m_surface;
};

cairo_t and cairo_surface_t are types defined by the Cairo graphics library.

The problem I have is that if I want to use this class or its derived classes from another library or application, I need to include the cairo headers as well because I am “leaking” the cairo types out through the CairoRenderer header. I want this class (or any subclass of it) in the same library to be usable externally without needing to include the cairo header or link against the cairo libraries.

So the next thing I tried was to use the pimpl technique as per the Wikipedia example because it looked like it could do what I wanted to achieve:

CairoRenderer.h (abbreviated)

class CairoRenderer
{
...
protected:
    struct CairoRendererImpl;
    CairoRendererImpl* m_pimpl;
};

CairoRenderer.cpp (abbreviated)

#include "CairoRenderer.h"
#include "cairo.h"

....

struct CairoRenderer::CairoRendererImpl 
{
public:
    CairoRendererImpl() : m_surface(NULL), m_context(NULL) { }
    ~CairoRendererImpl() 
    {
        cairo_surface_destroy(m_surface);
        cairo_destroy(m_context);
    }

    void Initialize(cairo_t* context, cairo_surface_t* surface)
    {
        m_context = context;
        m_surface = surface;
    }

    cairo_surface_t* surface() { return m_surface; }
    cairo_t* context() { return m_context; }

private:
    cairo_surface_t* m_surface;
    cairo_t* m_context;
};

CairoRenderer::CairoRenderer() : m_pimpl(new CairoRendererImpl()) { ... }

CairoRenderer::~CairoRenderer() { delete m_pimpl; }

The problem I have is when I try to access the m_pimpl member from a derived class, I get the compiler error:

error C2027: use of undefined type 'CairoRenderer::CairoRendererImpl'

Am I doing pimpl wrong? Or is what I want to do even possible?

  • 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-05-26T04:04:34+00:00Added an answer on May 26, 2026 at 4:04 am

    You are using the pimpl idiom correctly, and that is your problem. You have hidden the definition of CairoRendererImpl from all external code, including the code in derived classes.

    First of all I would like to call into question the value of having a base class that has data members and a non-virtual destructor. You should look at the underlying reasons that you want to subclass CairoRenderer, and consider alternative solutions.

    If you do want to support subclassing, but only for the classes within your library, then you should put the definition of CairoRendererImpl into a shared header file that can be included by the implementation files of all of the relevant classes in the CairoRenderer heirachy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a template class defined in a header file like this. Here I
I have got a map defined inside a class in header file like this:
All, i have the following model defined, class header(models.Model): title = models.CharField(max_length = 255)
I have a class defined as public class viewGroups extends ListActivity Somewhere in the
I have a class defined as: class Obj { public: int width, height; Obj(int
We have a class Car defined like this in a car.rb file class Car
I have a template class defined like so: template <class T> class Command {
I have a class that defined a user defined operator for a TCHAR*, like
I have a few properties defined in my header file like so @property (assign)
I have a header file: class A { public: DeviceProxyPtr GetDeviceProxy(); }; DeviceProxyPtr is

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.