Click here to Skip to main content
15,897,718 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionsql Pin
albertodiprima21-Aug-10 17:34
albertodiprima21-Aug-10 17:34 
AnswerRe: sql Pin
Dr.Walt Fair, PE21-Aug-10 18:47
professionalDr.Walt Fair, PE21-Aug-10 18:47 
GeneralRe: sql Pin
albertodiprima21-Aug-10 18:52
albertodiprima21-Aug-10 18:52 
QuestionHow to postpone implementation of abstract class in c++ Pin
tasumisra20-Aug-10 17:49
tasumisra20-Aug-10 17:49 
AnswerRe: How to postpone implementation of abstract class in c++ Pin
Tim Craig20-Aug-10 18:09
Tim Craig20-Aug-10 18:09 
GeneralRe: How to postpone implementation of abstract class in c++ Pin
tasumisra20-Aug-10 18:21
tasumisra20-Aug-10 18:21 
GeneralRe: How to postpone implementation of abstract class in c++ Pin
Aescleal20-Aug-10 21:15
Aescleal20-Aug-10 21:15 
AnswerRe: How to postpone implementation of abstract class in c++ PinPopular
Aescleal20-Aug-10 21:11
Aescleal20-Aug-10 21:11 
The best way of avoiding the need to implement member functions (C++ doesn't have methods) is to avoid deriving a class from an abstract class.

So the first thing to ask is... why are you writing code like you have in your main? Derived doesn't actually need to implement any abstract classes so just implement what you need to get your code compiling:

class adder
{
    public:
        int add( int i, int j ) const { return i + j; }
};

int main()
{
    std::cout << adder().add( 12, 34 ) << std::endl;
}


You only need abstract classes as your code gets bigger and you want to start cutting down on the dependencies between lumps of code. You use abstract classes as a design tool to avoid most of your code needing to know what concrete types they're dealing with.

If on the other hand you've got an interface you need to implement to use a particular lump of code then you haven't got a lot of choice but to implement the member functions. You could take the Java route and implement a minimal class and then derive from that:

class adder
{
     public:
        virtual int add( int i, int j ) = 0;
};

class minimal_adder
{
    public:
        virtual int add( int, int ) { return 0; }
};

But that can turn into a maintenance nightmare (you have to look at two implementations to find out where a member function is implemented, not just one. It gets worse when some wit adds another level, then another...).

So the points here are:

- Don't use an abstract class until you need to, never do it "just in case" [1]
- When you create abstract classes try and create them from the existing interface of a concrete class. You'll at least know there's client code (and unit tests) ready to use your new abstract class against
- Only use Java style stub implementations as a last resort (some chunk of client code is expecting an interface with 30 member functions, half of which you have no idea what the contracts are)

Cheers,

Ash

[1] Needing to includes using one as a firewall between code you're writing and code your colleagues are writing. If you sit down with a co-worker that needs a service from code you're writing hack out a quick interface together, stub implement it for them and then take your time implementing it properly.
AnswerRe: How to postpone implementation of abstract class in c++ Pin
Niklas L20-Aug-10 22:04
Niklas L20-Aug-10 22:04 
GeneralRe: How to postpone implementation of abstract class in c++ Pin
tasumisra20-Aug-10 22:42
tasumisra20-Aug-10 22:42 
QuestionPreventing CD copy Pin
RomTibi20-Aug-10 7:32
RomTibi20-Aug-10 7:32 
QuestionRe: Preventing CD copy Pin
David Crow20-Aug-10 10:50
David Crow20-Aug-10 10:50 
AnswerRe: Preventing CD copy Pin
RomTibi22-Aug-10 5:40
RomTibi22-Aug-10 5:40 
AnswerRe: Preventing CD copy PinPopular
Emilio Garavaglia20-Aug-10 11:36
Emilio Garavaglia20-Aug-10 11:36 
GeneralRe: Preventing CD copy Pin
RomTibi21-Aug-10 21:16
RomTibi21-Aug-10 21:16 
Questiondocument support in MFC dll Pin
MKC00220-Aug-10 4:35
MKC00220-Aug-10 4:35 
AnswerRe: document support in MFC dll Pin
Eugen Podsypalnikov20-Aug-10 5:43
Eugen Podsypalnikov20-Aug-10 5:43 
GeneralRe: document support in MFC dll Pin
Niklas L20-Aug-10 5:46
Niklas L20-Aug-10 5:46 
JokeRe: document support in MFC dll Pin
Eugen Podsypalnikov20-Aug-10 5:57
Eugen Podsypalnikov20-Aug-10 5:57 
GeneralRe: document support in MFC dll Pin
Nuri Ismail20-Aug-10 7:01
Nuri Ismail20-Aug-10 7:01 
GeneralRe: document support in MFC dll Pin
MKC00220-Aug-10 9:01
MKC00220-Aug-10 9:01 
GeneralRe: document support in MFC dll Pin
Niklas L20-Aug-10 10:35
Niklas L20-Aug-10 10:35 
AnswerRe: document support in MFC dll Pin
Niklas L20-Aug-10 5:46
Niklas L20-Aug-10 5:46 
QuestionHow i can change the width of scrollbar in MFC SDI application? [Moved] Pin
humais20-Aug-10 4:04
humais20-Aug-10 4:04 
AnswerRe: How i can change the width of scrollbar in MFC SDI application? Pin
Nish Nishant20-Aug-10 6:30
sitebuilderNish Nishant20-Aug-10 6:30 

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.