Click here to Skip to main content
15,914,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: urgent Pin
john563218-Mar-08 0:08
john563218-Mar-08 0:08 
GeneralRe: urgent Pin
Naveen18-Mar-08 0:19
Naveen18-Mar-08 0:19 
GeneralRe: urgent Pin
john563218-Mar-08 0:29
john563218-Mar-08 0:29 
GeneralRe: urgent Pin
fat_boy18-Mar-08 2:47
fat_boy18-Mar-08 2:47 
GeneralInheritance in Pimpl idiom Pin
George_George17-Mar-08 19:31
George_George17-Mar-08 19:31 
GeneralRe: Inheritance in Pimpl idiom Pin
Maxwell Chen17-Mar-08 20:01
Maxwell Chen17-Mar-08 20:01 
GeneralRe: Inheritance in Pimpl idiom Pin
George_George17-Mar-08 22:01
George_George17-Mar-08 22:01 
AnswerRe: Inheritance in Pimpl idiom [modified] Pin
Maxwell Chen17-Mar-08 20:43
Maxwell Chen17-Mar-08 20:43 
The below is the original Pimpl model. The opaque pointer is the private member.

To test this with Visual C++ (2005), you need to put the declarations of class X and class X::XImpl with their member function prototypes in individual .h files, and put the implementations of member functions in individual .cpp files.
// x.h
class X
{
private:
  class XImpl;
  XImpl* pimpl_;
public:
  bool Foo(long);
protected:
  int Bar(short);
};
// ximpl.h
class X::XImpl
{
public:
  bool Function();
  // ...
};
// x.cpp
bool X::Foo(long v)
{
  return pimpl_->Function();
}
// ximpl.cpp
bool X::XImpl::Function()
{
  // ...
  return true;
}


What does it mean To make XImpl entirely the class X would have been?
That is, you move X::Foo and X::Bar into class X::XImpl.

Code snippet below.
// x.h
class X2  // New generation.
{
private:
  class XImpl;
  XImpl* pimpl_;
public:
  bool Foo(long); // Leave this as the only public interface.
};
// ximpl.h
class X2::XImpl
{
public:
  bool Function();
protected:
  int Bar(short); // Move all the implementations of X into here, so no backpointer is needed.
};

How will we use this revision? Still the same.
X2 obj;
if(obj.Foo() /* invoke the opaque Function() */ ) {
 // ...
}


So now we talk about the inheritance. See the comments in the code snippet below.
class Y : public X2
{
public:
  bool Test() {
    // Oops!! 
    // No access to Bar().
    // No access to Pimpl.
    return false;
  }
  // ...
};


  Maxwell Chen

modified on Tuesday, March 18, 2008 4:04 AM

GeneralRe: Inheritance in Pimpl idiom Pin
George_George17-Mar-08 22:14
George_George17-Mar-08 22:14 
AnswerRe: Inheritance in Pimpl idiom Pin
Maxwell Chen17-Mar-08 23:00
Maxwell Chen17-Mar-08 23:00 
GeneralRe: Inheritance in Pimpl idiom Pin
George_George17-Mar-08 23:26
George_George17-Mar-08 23:26 
GeneralRe: Inheritance in Pimpl idiom Pin
Maxwell Chen17-Mar-08 23:53
Maxwell Chen17-Mar-08 23:53 
GeneralRe: Inheritance in Pimpl idiom Pin
George_George18-Mar-08 0:17
George_George18-Mar-08 0:17 
GeneralCopy File and long file path Pin
vikramlinux17-Mar-08 19:26
vikramlinux17-Mar-08 19:26 
GeneralRe: Copy File and long file path Pin
Michael Dunn17-Mar-08 19:45
sitebuilderMichael Dunn17-Mar-08 19:45 
GeneralRe: Copy File and long file path Pin
vikramlinux17-Mar-08 20:23
vikramlinux17-Mar-08 20:23 
Questionshutdown function for CWinApp() Pin
rp_suman17-Mar-08 18:49
rp_suman17-Mar-08 18:49 
GeneralRe: shutdown function for CWinApp() Pin
rp_suman17-Mar-08 18:53
rp_suman17-Mar-08 18:53 
GeneralRe: shutdown function for CWinApp() Pin
Rajkumar R17-Mar-08 21:37
Rajkumar R17-Mar-08 21:37 
GeneralRe: shutdown function for CWinApp() Pin
rp_suman18-Mar-08 4:30
rp_suman18-Mar-08 4:30 
QuestionChange writing direction in RUN TIME (Edit Box) Pin
Joseph Marzbani17-Mar-08 9:50
Joseph Marzbani17-Mar-08 9:50 
GeneralRe: Change writing direction in RUN TIME (Edit Box) Pin
CPallini17-Mar-08 9:53
mveCPallini17-Mar-08 9:53 
GeneralRe: Change writing direction in RUN TIME (Edit Box) Pin
David Crow17-Mar-08 10:57
David Crow17-Mar-08 10:57 
GeneralRe: Change writing direction in RUN TIME (Edit Box) Pin
led mike17-Mar-08 11:39
led mike17-Mar-08 11:39 
Questionbackground worker Pin
Adnan Merter17-Mar-08 8:00
Adnan Merter17-Mar-08 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.