Click here to Skip to main content
15,886,518 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
leon de boer9-Oct-16 23:23
leon de boer9-Oct-16 23:23 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
Richard MacCutchan9-Oct-16 23:25
mveRichard MacCutchan9-Oct-16 23:25 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
Vaclav_10-Oct-16 4:17
Vaclav_10-Oct-16 4:17 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
leon de boer10-Oct-16 4:32
leon de boer10-Oct-16 4:32 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
Vaclav_10-Oct-16 13:20
Vaclav_10-Oct-16 13:20 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
leon de boer10-Oct-16 17:02
leon de boer10-Oct-16 17:02 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
Vaclav_11-Oct-16 7:01
Vaclav_11-Oct-16 7:01 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
leon de boer11-Oct-16 17:26
leon de boer11-Oct-16 17:26 
You said ... "To do what you suggest , which make perfect sense, I would have to change my other classes using Print methods to use the Print object."

No you don't all you need to do is create a printer class at initialization, lets say you have a private variable printer class called "ThePrinter". All it means is at the moment you are calling the inherited methods of the printer class directly so xyz_func(); so instead of that it would become ThePrinter.xyz_Func(); Really from a code point it's that simple a small change in the constructor and the name of the held printer infront of the printer class methods you are directly calling.

Besides making your interface a hell of a lot smaller and removing bloating code and data in your class it also allows you to do things you can't do like change the printer device on the fly or pass the printer class to another object or a block of code. If you want to share the printer, so two different classes can write to the exact same printer (which may be likely in your case), you get one class to make the printer and then simply make a function on that class so the other classes can get a pointer to the printer. So the class that has the printer does this via a function GetMyPrinter
class IHavePrinter{
    public:
    PrinterClass* GetMyPrinter(void); // Return the created printer is a public function
    private:
    PrinterClass ThePrinter;   // The actual created printer in this classes constructor
}

IHavePrinter:: PrinterClass* GetMyPrinter(void){
    return(&ThePrinter);       // Return pointer to the created printer
}


That is the point of keeping classes detached so you can do things you can't possibly do if you bind them into your object inheritance and you stop the vicious cross connection you are getting. I think most of your dependency issues is actually cause by your inheritance scheme and wouldn't exist if you did it properly.

You could just have exposed the printer object as a public but the few lines to pass it on a function means that later on if you want to track who is using the printer or know if it's in use you can modify that function to track that etc. So a bit of forward planning built into the concept and trying to keep the classes as detached as possible not accessing each others fields.
In vino veritas


modified 11-Oct-16 23:43pm.

GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
Vaclav_12-Oct-16 14:42
Vaclav_12-Oct-16 14:42 
GeneralRe: One more error using function pointers - void value not ignored as it ought to be Pin
leon de boer12-Oct-16 17:09
leon de boer12-Oct-16 17:09 
QuestionMore basic C++ questions - may I ask? Pin
Vaclav_8-Oct-16 15:24
Vaclav_8-Oct-16 15:24 
AnswerRe: More basic C++ questions - may I ask? Pin
Midi_Mick8-Oct-16 15:52
professionalMidi_Mick8-Oct-16 15:52 
AnswerRe: More basic C++ questions - may I ask? Pin
Richard MacCutchan8-Oct-16 20:37
mveRichard MacCutchan8-Oct-16 20:37 
GeneralRe: More basic C++ questions - may I ask? Pin
Vaclav_9-Oct-16 6:20
Vaclav_9-Oct-16 6:20 
GeneralRe: More basic C++ questions - may I ask? Pin
Richard MacCutchan9-Oct-16 6:27
mveRichard MacCutchan9-Oct-16 6:27 
GeneralRe: More basic C++ questions - may I ask? Pin
Graham Breach9-Oct-16 21:46
Graham Breach9-Oct-16 21:46 
GeneralRe: More basic C++ questions - may I ask? Pin
Richard MacCutchan9-Oct-16 23:00
mveRichard MacCutchan9-Oct-16 23:00 
AnswerRe: More basic C++ questions - may I ask? Pin
Ratul Thakur10-Oct-16 21:42
Ratul Thakur10-Oct-16 21:42 
GeneralRe: More basic C++ questions - may I ask? Pin
David Crow11-Oct-16 6:23
David Crow11-Oct-16 6:23 
QuestionHow to initialize a CString array in MSVS C++ 2015 Pin
Member 94114717-Oct-16 8:36
Member 94114717-Oct-16 8:36 
AnswerRe: How to initialize a CString array in MSVS C++ 2015 Pin
jeron17-Oct-16 10:15
jeron17-Oct-16 10:15 
GeneralRe: How to initialize a CString array in MSVS C++ 2015 Pin
Member 941147111-Oct-16 8:48
Member 941147111-Oct-16 8:48 
GeneralRe: How to initialize a CString array in MSVS C++ 2015 Pin
Victor Nijegorodov12-Oct-16 2:57
Victor Nijegorodov12-Oct-16 2:57 
AnswerRe: How to initialize a CString array in MSVS C++ 2015 Pin
Chris Losinger8-Oct-16 6:58
professionalChris Losinger8-Oct-16 6:58 
QuestionUsing / accessing function pointer declaration externally Pin
Vaclav_6-Oct-16 11:05
Vaclav_6-Oct-16 11:05 

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.