[{"data":1,"prerenderedAt":395},["ShallowReactive",2],{"content-hero-\u002Fcodesnippets\u002Fcpp\u002Fcsharp-interface-equivalent":3,"content-query-ynVbRjlSrJ":6},{"title":4,"imageUrl":5},"C++ equivalent implementation of C# interface","\u002Fimages\u002Fthumbnails\u002Fc.gif",{"_path":7,"_dir":8,"_draft":9,"_partial":9,"_locale":10,"title":4,"description":11,"imageUrl":5,"body":12,"_type":389,"_id":390,"_source":391,"_file":392,"_stem":393,"_extension":394},"\u002Fcodesnippets\u002Fcpp\u002Fcsharp-interface-equivalent","cpp",false,"","Map a C# ICompte-style interface to a pure abstract C++ class with virtual methods.",{"type":13,"children":14,"toc":385},"root",[15,23,28,33,40,194,200,379],{"type":16,"tag":17,"props":18,"children":19},"element","p",{},[20],{"type":21,"value":22},"text","Sometimes when learning from one language to another one, you may have to adapt your habit to the paradigm of language and it’s evolution degree.",{"type":16,"tag":17,"props":24,"children":25},{},[26],{"type":21,"value":27},"Interface for C# developer is one of the pillar of SOLID Implementation Principles. In the C++ development the equivalence is not trivial enough in my opinion.",{"type":16,"tag":17,"props":29,"children":30},{},[31],{"type":21,"value":32},"Response: virtual C++ classes",{"type":16,"tag":34,"props":35,"children":37},"h2",{"id":36},"interface-in-c",[38],{"type":21,"value":39},"Interface in C#",{"type":16,"tag":41,"props":42,"children":46},"pre",{"className":43,"code":44,"language":45,"meta":10,"style":10},"language-csharp shiki shiki-themes github-light github-dark","\u002F\u002F ICompte.cs file\npublic interface ICompte\n{\n    double retirerArgent(double montant);\n    double ajouterArgent(double montant);\n    double Solde { get; }\n}\n","csharp",[47],{"type":16,"tag":48,"props":49,"children":50},"code",{"__ignoreMap":10},[51,63,84,94,128,157,185],{"type":16,"tag":52,"props":53,"children":56},"span",{"class":54,"line":55},"line",1,[57],{"type":16,"tag":52,"props":58,"children":60},{"style":59},"--shiki-default:#6A737D;--shiki-dark:#6A737D",[61],{"type":21,"value":62},"\u002F\u002F ICompte.cs file\n",{"type":16,"tag":52,"props":64,"children":66},{"class":54,"line":65},2,[67,73,78],{"type":16,"tag":52,"props":68,"children":70},{"style":69},"--shiki-default:#D73A49;--shiki-dark:#F97583",[71],{"type":21,"value":72},"public",{"type":16,"tag":52,"props":74,"children":75},{"style":69},[76],{"type":21,"value":77}," interface",{"type":16,"tag":52,"props":79,"children":81},{"style":80},"--shiki-default:#6F42C1;--shiki-dark:#B392F0",[82],{"type":21,"value":83}," ICompte\n",{"type":16,"tag":52,"props":85,"children":87},{"class":54,"line":86},3,[88],{"type":16,"tag":52,"props":89,"children":91},{"style":90},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[92],{"type":21,"value":93},"{\n",{"type":16,"tag":52,"props":95,"children":97},{"class":54,"line":96},4,[98,103,108,113,118,123],{"type":16,"tag":52,"props":99,"children":100},{"style":69},[101],{"type":21,"value":102},"    double",{"type":16,"tag":52,"props":104,"children":105},{"style":80},[106],{"type":21,"value":107}," retirerArgent",{"type":16,"tag":52,"props":109,"children":110},{"style":90},[111],{"type":21,"value":112},"(",{"type":16,"tag":52,"props":114,"children":115},{"style":69},[116],{"type":21,"value":117},"double",{"type":16,"tag":52,"props":119,"children":120},{"style":80},[121],{"type":21,"value":122}," montant",{"type":16,"tag":52,"props":124,"children":125},{"style":90},[126],{"type":21,"value":127},");\n",{"type":16,"tag":52,"props":129,"children":131},{"class":54,"line":130},5,[132,136,141,145,149,153],{"type":16,"tag":52,"props":133,"children":134},{"style":69},[135],{"type":21,"value":102},{"type":16,"tag":52,"props":137,"children":138},{"style":80},[139],{"type":21,"value":140}," ajouterArgent",{"type":16,"tag":52,"props":142,"children":143},{"style":90},[144],{"type":21,"value":112},{"type":16,"tag":52,"props":146,"children":147},{"style":69},[148],{"type":21,"value":117},{"type":16,"tag":52,"props":150,"children":151},{"style":80},[152],{"type":21,"value":122},{"type":16,"tag":52,"props":154,"children":155},{"style":90},[156],{"type":21,"value":127},{"type":16,"tag":52,"props":158,"children":160},{"class":54,"line":159},6,[161,165,170,175,180],{"type":16,"tag":52,"props":162,"children":163},{"style":69},[164],{"type":21,"value":102},{"type":16,"tag":52,"props":166,"children":167},{"style":80},[168],{"type":21,"value":169}," Solde",{"type":16,"tag":52,"props":171,"children":172},{"style":90},[173],{"type":21,"value":174}," { ",{"type":16,"tag":52,"props":176,"children":177},{"style":69},[178],{"type":21,"value":179},"get",{"type":16,"tag":52,"props":181,"children":182},{"style":90},[183],{"type":21,"value":184},"; }\n",{"type":16,"tag":52,"props":186,"children":188},{"class":54,"line":187},7,[189],{"type":16,"tag":52,"props":190,"children":191},{"style":90},[192],{"type":21,"value":193},"}\n",{"type":16,"tag":34,"props":195,"children":197},{"id":196},"c-equivalent-implementation",[198],{"type":21,"value":199},"C++ equivalent implementation",{"type":16,"tag":41,"props":201,"children":204},{"className":202,"code":203,"language":8,"meta":10,"style":10},"language-cpp shiki shiki-themes github-light github-dark","\u002F\u002F ICompte.h file\nclass ICompte\n{\npublic:\n    virtual double retirerArgent(double montant) = 0;\n    virtual double ajouterArgent(double montant) = 0;\n    virtual double getSolde() = 0;\n};\n",[205],{"type":16,"tag":48,"props":206,"children":207},{"__ignoreMap":10},[208,216,228,235,243,294,337,370],{"type":16,"tag":52,"props":209,"children":210},{"class":54,"line":55},[211],{"type":16,"tag":52,"props":212,"children":213},{"style":59},[214],{"type":21,"value":215},"\u002F\u002F ICompte.h file\n",{"type":16,"tag":52,"props":217,"children":218},{"class":54,"line":65},[219,224],{"type":16,"tag":52,"props":220,"children":221},{"style":69},[222],{"type":21,"value":223},"class",{"type":16,"tag":52,"props":225,"children":226},{"style":80},[227],{"type":21,"value":83},{"type":16,"tag":52,"props":229,"children":230},{"class":54,"line":86},[231],{"type":16,"tag":52,"props":232,"children":233},{"style":90},[234],{"type":21,"value":93},{"type":16,"tag":52,"props":236,"children":237},{"class":54,"line":96},[238],{"type":16,"tag":52,"props":239,"children":240},{"style":69},[241],{"type":21,"value":242},"public:\n",{"type":16,"tag":52,"props":244,"children":245},{"class":54,"line":130},[246,251,256,260,264,268,273,278,283,289],{"type":16,"tag":52,"props":247,"children":248},{"style":69},[249],{"type":21,"value":250},"    virtual",{"type":16,"tag":52,"props":252,"children":253},{"style":69},[254],{"type":21,"value":255}," double",{"type":16,"tag":52,"props":257,"children":258},{"style":80},[259],{"type":21,"value":107},{"type":16,"tag":52,"props":261,"children":262},{"style":90},[263],{"type":21,"value":112},{"type":16,"tag":52,"props":265,"children":266},{"style":69},[267],{"type":21,"value":117},{"type":16,"tag":52,"props":269,"children":271},{"style":270},"--shiki-default:#E36209;--shiki-dark:#FFAB70",[272],{"type":21,"value":122},{"type":16,"tag":52,"props":274,"children":275},{"style":90},[276],{"type":21,"value":277},") ",{"type":16,"tag":52,"props":279,"children":280},{"style":69},[281],{"type":21,"value":282},"=",{"type":16,"tag":52,"props":284,"children":286},{"style":285},"--shiki-default:#005CC5;--shiki-dark:#79B8FF",[287],{"type":21,"value":288}," 0",{"type":16,"tag":52,"props":290,"children":291},{"style":90},[292],{"type":21,"value":293},";\n",{"type":16,"tag":52,"props":295,"children":296},{"class":54,"line":159},[297,301,305,309,313,317,321,325,329,333],{"type":16,"tag":52,"props":298,"children":299},{"style":69},[300],{"type":21,"value":250},{"type":16,"tag":52,"props":302,"children":303},{"style":69},[304],{"type":21,"value":255},{"type":16,"tag":52,"props":306,"children":307},{"style":80},[308],{"type":21,"value":140},{"type":16,"tag":52,"props":310,"children":311},{"style":90},[312],{"type":21,"value":112},{"type":16,"tag":52,"props":314,"children":315},{"style":69},[316],{"type":21,"value":117},{"type":16,"tag":52,"props":318,"children":319},{"style":270},[320],{"type":21,"value":122},{"type":16,"tag":52,"props":322,"children":323},{"style":90},[324],{"type":21,"value":277},{"type":16,"tag":52,"props":326,"children":327},{"style":69},[328],{"type":21,"value":282},{"type":16,"tag":52,"props":330,"children":331},{"style":285},[332],{"type":21,"value":288},{"type":16,"tag":52,"props":334,"children":335},{"style":90},[336],{"type":21,"value":293},{"type":16,"tag":52,"props":338,"children":339},{"class":54,"line":187},[340,344,348,353,358,362,366],{"type":16,"tag":52,"props":341,"children":342},{"style":69},[343],{"type":21,"value":250},{"type":16,"tag":52,"props":345,"children":346},{"style":69},[347],{"type":21,"value":255},{"type":16,"tag":52,"props":349,"children":350},{"style":80},[351],{"type":21,"value":352}," getSolde",{"type":16,"tag":52,"props":354,"children":355},{"style":90},[356],{"type":21,"value":357},"() ",{"type":16,"tag":52,"props":359,"children":360},{"style":69},[361],{"type":21,"value":282},{"type":16,"tag":52,"props":363,"children":364},{"style":285},[365],{"type":21,"value":288},{"type":16,"tag":52,"props":367,"children":368},{"style":90},[369],{"type":21,"value":293},{"type":16,"tag":52,"props":371,"children":373},{"class":54,"line":372},8,[374],{"type":16,"tag":52,"props":375,"children":376},{"style":90},[377],{"type":21,"value":378},"};\n",{"type":16,"tag":380,"props":381,"children":382},"style",{},[383],{"type":21,"value":384},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":10,"searchDepth":65,"depth":65,"links":386},[387,388],{"id":36,"depth":65,"text":39},{"id":196,"depth":65,"text":199},"markdown","content:codesnippets:cpp:csharp-interface-equivalent.md","content","codesnippets\u002Fcpp\u002Fcsharp-interface-equivalent.md","codesnippets\u002Fcpp\u002Fcsharp-interface-equivalent","md",1779013873257]