Search Results

Search found 2 results on 1 pages for 'sinec'.

Page 1/1 | 1 

  • Why only the constant expression can be used as case expression in Switch statement?

    - by sinec
    Hi, what is bothering me is that I can't found an info regarding the question from the title. I found that assembly form the Switch-case statement is compiled into bunch of (MS VC 2008 compiler) cmp and je calls: 0041250C mov eax,dword ptr [i] 0041250F mov dword ptr [ebp-100h],eax 00412515 cmp dword ptr [ebp-100h],1 0041251C je wmain+52h (412532h) 0041251E cmp dword ptr [ebp-100h],2 00412525 je wmain+5Bh (41253Bh) 00412527 cmp dword ptr [ebp-100h],3 0041252E je wmain+64h (412544h) 00412530 jmp wmain+6Bh (41254Bh) where for above code will in case that if condition (i) is equal to 2, jump to address 41253Bh and do execution form there (at 41253Bh starts the code for 'case 2:' block) What I don't understand is why in case that,for instance, function is used as 'case expression', why first function couldn't be evaluated and then its result compared with the condition? Am I missing something? Thank you in advance

    Read the article

  • Implement abstract class as a local class? pros and cons

    - by sinec
    Hi, for some reason I'm thinking on implementing interface within a some function(method) as local class. Consider following: class A{ public: virtual void MethodToOverride() = 0; }; A * GetPtrToAImplementation(){ class B : public A { public: B(){} ~B(){} void MethodToOverride() { //do something } }; return static_cast<A *>(new B()); } int _tmain(int argc, _TCHAR* argv[]) { A * aInst = GetPtrToAImplementation(); aInst->MethodToOverride(); delete aInst; return 0; } the reason why I'm doing this are: I'm lazy to implement class (B) in separate files MethodToOverride just delegates call to other class Class B shouldn't be visible to other users no need to worry about deleting aInst since smart pointers are used in real implementation So my question is if I'm doing this right? Thanks in advance!

    Read the article

1