Click here to Skip to main content
15,845,055 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
Amrit Agr6-Nov-16 23:06
Amrit Agr6-Nov-16 23:06 
AnswerRe: How explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
Richard MacCutchan7-Nov-16 1:18
mveRichard MacCutchan7-Nov-16 1:18 
AnswerRe: How explicit , volatile and mutable keywords works INTERNALLY in C++ ? Pin
leon de boer7-Nov-16 9:15
leon de boer7-Nov-16 9:15 
GeneralPlease help Pin
Ahmed Adel5-Nov-16 4:20
Ahmed Adel5-Nov-16 4:20 
GeneralRe: Please help Pin
Richard MacCutchan5-Nov-16 22:01
mveRichard MacCutchan5-Nov-16 22:01 
GeneralRe: Please help Pin
leon de boer6-Nov-16 5:49
leon de boer6-Nov-16 5:49 
PraiseRe: Please help Pin
Ahmed Adel6-Nov-16 6:10
Ahmed Adel6-Nov-16 6:10 
QuestionPattern review C++: using structs with pure virtual methods in place of interfaces Pin
Member 128328324-Nov-16 6:58
Member 128328324-Nov-16 6:58 
I just started to learn C++, coming from a C# and Java background.
I like to use interfaces in my code. In C++ though they do not exist so instead I make structs with pure virtual methods. I'm interested in opinions on different conventions used.

My questions are:

1) From what I understand there is no difference between struct and class besides the default accessor, but it is common place to see struct being used when the class is of a smaller size. Therefore I decided as a convention to use struct when writing interfaces since the way struct is viewed by programmers more closely resembles an interface. Are there any other conventions on this issue or is my convention bad or could cause confusion in any way?

2) Since an interface only has pure virtual and provides no implementation (most of the times, default methods are now a thing in Java) I thought it would be logical to only make a header file for it, instead of making both a .cpp and a .h file. Since a .cpp file is supposed to have the implementation and the .h file is supposed to have the method prototypes. Again, are there any other conventions on this issue or is my convention bad or could cause confusion in any way?

Example:

ISayHello.h
C++
struct IRender
{
    virtual void render() = 0;
}


ImplementationExample.cpp
C++
class Sprite : public IRender
{
public:
    void render() override
    {
        //code goes here
    }
}


What I have tried:

NOTE: My intention is to get the opinion of those with more experience on how my pattern works, if it has problems, and if there is any other convention on issue that my convention is addressing. If you think the question is off topic I would appreciate if you could redirect me to a better place to ask my question. This question for example was marked as off topic on the Code Review Stack Exchange, though in my opinion asking for review on a pattern you in your code is not off topic.
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
Chris Losinger4-Nov-16 9:23
professionalChris Losinger4-Nov-16 9:23 
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
leon de boer4-Nov-16 9:48
leon de boer4-Nov-16 9:48 
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
«_Superman_»5-Nov-16 22:42
professional«_Superman_»5-Nov-16 22:42 
AnswerRe: Pattern review C++: using structs with pure virtual methods in place of interfaces Pin
Daniel Pfeffer6-Nov-16 1:35
professionalDaniel Pfeffer6-Nov-16 1:35 
QuestionMouse out of dialog Pin
_Flaviu3-Nov-16 5:07
_Flaviu3-Nov-16 5:07 
AnswerRe: Mouse out of dialog Pin
leon de boer3-Nov-16 5:21
leon de boer3-Nov-16 5:21 
QuestionRe: Mouse out of dialog Pin
David Crow3-Nov-16 16:42
David Crow3-Nov-16 16:42 
AnswerRe: Mouse out of dialog Pin
_Flaviu3-Nov-16 22:44
_Flaviu3-Nov-16 22:44 
GeneralRe: Mouse out of dialog Pin
Richard MacCutchan3-Nov-16 23:04
mveRichard MacCutchan3-Nov-16 23:04 
GeneralRe: Mouse out of dialog Pin
leon de boer3-Nov-16 23:10
leon de boer3-Nov-16 23:10 
GeneralRe: Mouse out of dialog Pin
_Flaviu4-Nov-16 0:12
_Flaviu4-Nov-16 0:12 
QuestionSharing some humour Pin
leon de boer2-Nov-16 6:40
leon de boer2-Nov-16 6:40 
JokeRe: Sharing some humour Pin
Randor 2-Nov-16 18:34
professional Randor 2-Nov-16 18:34 
GeneralRe: Sharing some humour Pin
leon de boer2-Nov-16 19:57
leon de boer2-Nov-16 19:57 
AnswerRe: Sharing some humour Pin
Daniel Pfeffer2-Nov-16 23:23
professionalDaniel Pfeffer2-Nov-16 23:23 
GeneralRe: Sharing some humour Pin
leon de boer3-Nov-16 4:14
leon de boer3-Nov-16 4:14 
GeneralRe: Sharing some humour Pin
Daniel Pfeffer3-Nov-16 4:34
professionalDaniel Pfeffer3-Nov-16 4:34 

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.