Click here to Skip to main content
15,887,376 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Migrating old project to VS2008 - resource file errors Pin
charlieg4-Aug-16 8:07
charlieg4-Aug-16 8:07 
GeneralRe: Migrating old project to VS2008 - resource file errors Pin
Richard MacCutchan4-Aug-16 8:22
mveRichard MacCutchan4-Aug-16 8:22 
GeneralRe: Migrating old project to VS2008 - resource file errors Pin
leon de boer7-Aug-16 7:47
leon de boer7-Aug-16 7:47 
GeneralRe: Migrating old project to VS2008 - resource file errors Pin
charlieg8-Aug-16 2:02
charlieg8-Aug-16 2:02 
GeneralRe: Migrating old project to VS2008 - resource file errors Pin
leon de boer8-Aug-16 7:11
leon de boer8-Aug-16 7:11 
GeneralRe: Migrating old project to VS2008 - resource file errors Pin
charlieg9-Aug-16 7:50
charlieg9-Aug-16 7:50 
AnswerRe: Migrating old project to VS2008 - resource file errors Pin
charlieg24-Sep-16 0:48
charlieg24-Sep-16 0:48 
Questionhow to be sure each child class inherits a method? Pin
FriendOfAsherah2-Aug-16 19:58
FriendOfAsherah2-Aug-16 19:58 
I have a straight class hierarchy.
The base class only has a method F() which calls another method P().
This method P() has to be implemented in all of the child classes and is called by polymorphism.

How can I get sure (at compile time) that all child classes implement this method P()?
C#
class CBase 
{
private:
  virtual void P() { printf("CBase::P\n"); }
public:
  void F() { printf("Base: F()->P(): "), P(); }
};

class C1 : public CBase
{
  private:
    virtual void P() override { printf("C1::P\n"); }
};
class C2 : public C1
{
  private:
    virtual void P() override { printf("C2::P\n"); }
};

void main()
{
  CBase* p = new CBase();
  p->F();
  p = new C1();
  p->F();
  p = new C2();
  p->F();
}

The above is the structure, when all is correct and will result in:
Base: F()->P(): CBase::P
Base: F()->P(): C1::P
Base: F()->P(): C2::P

Now I made a mistake and forgot to implement P() in class C1
C#
class C1 : public CBase
{
  private:
    //virtual void P() override { printf("C1::P\n"); }
};

the compiler doesn´t error and it will result in
Base: F()->P(): CBase::P
Base: F()->P(): CBase::P
Base: F()->P(): C2::P

The only Idea is to use an Interface declaring P() abstract.
But since C2 is derived from C1 from CBase how to do?
Followeing code will show up an error on missing P(), but also shows up warnings when all is correct:
warning C4584: 'C1': base class 'PI' is already base of 'CBase'
warning C4584: 'C2': base class 'PI' is already base of 'C1'

C#
struct PI
{
  virtual void P() abstract;
};

class CBase : public PI
{
private:
  virtual void P() { printf("CBase::P\n"); }
public:
  void F() { printf("Base: F()->P(): "), P(); }
};

class C1 : public CBase, public PI
{
  private:
    virtual void P() override { printf("C1::P\n"); }
};
class C2 : public C1, public PI
{
  private:
    virtual void P() override { printf("C2::P\n"); }
};

also it doesnt help at all because now I have to be sure to derive C1,C2, ... from PI too, not only from its parent

So what I need is "method P() has to be declared in all child classes!- error if it is not"

AnswerRe: how to be sure each child class inherits a method? Pin
Richard MacCutchan2-Aug-16 20:28
mveRichard MacCutchan2-Aug-16 20:28 
GeneralRe: how to be sure each child class inherits a method? Pin
FriendOfAsherah2-Aug-16 20:49
FriendOfAsherah2-Aug-16 20:49 
GeneralRe: how to be sure each child class inherits a method? Pin
Richard MacCutchan2-Aug-16 21:03
mveRichard MacCutchan2-Aug-16 21:03 
GeneralRe: how to be sure each child class inherits a method? Pin
FriendOfAsherah2-Aug-16 21:29
FriendOfAsherah2-Aug-16 21:29 
GeneralRe: how to be sure each child class inherits a method? Pin
Richard MacCutchan3-Aug-16 3:15
mveRichard MacCutchan3-Aug-16 3:15 
GeneralRe: how to be sure each child class inherits a method? Pin
FriendOfAsherah3-Aug-16 19:23
FriendOfAsherah3-Aug-16 19:23 
SuggestionRe: how to be sure each child class inherits a method? Pin
Krishnakumartg21-Sep-16 20:19
Krishnakumartg21-Sep-16 20:19 
QuestionCrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
ForNow2-Aug-16 16:38
ForNow2-Aug-16 16:38 
QuestionRe: CrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
Richard MacCutchan2-Aug-16 20:24
mveRichard MacCutchan2-Aug-16 20:24 
AnswerRe: CrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
ForNow2-Aug-16 23:25
ForNow2-Aug-16 23:25 
GeneralRe: CrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
Richard MacCutchan3-Aug-16 3:11
mveRichard MacCutchan3-Aug-16 3:11 
AnswerRe: CrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
leon de boer4-Aug-16 5:19
leon de boer4-Aug-16 5:19 
GeneralRe: CrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
ForNow4-Aug-16 5:29
ForNow4-Aug-16 5:29 
GeneralRe: Had a number of controls CTEXT and I didn't allocate Corresponding Ctatic Pointers thanks Pin
ForNow5-Aug-16 5:29
ForNow5-Aug-16 5:29 
QuestionRe: CrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
David Crow6-Aug-16 17:03
David Crow6-Aug-16 17:03 
AnswerRe: CrichEditCtrl::Find returns zero when second RichEdit is Created as a Child of A Different CDialog Pin
ForNow6-Aug-16 17:24
ForNow6-Aug-16 17:24 
QuestionUnhandled exception in ntdll.dll access violation reading location 0xFFFFFFFFFFFFFFFF Pin
ForNow1-Aug-16 8:04
ForNow1-Aug-16 8:04 

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.