Is it possible to avoid repeating the class name in the implementation file?

后端 未结 8 1976
迷失自我
迷失自我 2020-11-27 21:39

Is there a way to avoid the Graph:: repetition in the implementation file, yet still split the class into header + implementation? Such as in:

Header Fi

相关标签:
8条回答
  • I'm guessing this is to avoid lots of "unnecessary typing". Sadly there's no way to get rid of the scope (as many other answers have told you) however what I do personally is get the class defined with all my function prototypes in nice rows, then copy/paste into the implementation file then ctrl-c your ClassName:: on the clip board and run up the line with ctrl-v.

    0 讨论(0)
  • 2020-11-27 22:16
            //yes it is possible using preprocessor like this:
    
            #define $ ClassName //in .cpp 
    
        void $::Method1() 
        { 
        } 
    
        //or like this: in the header .h:
    
            #undef $
            #define $ ClassName' 
    
    // but you have to include the class header in last #include in your .cpp:
    
            #include "truc.h"
            #include "bidule.h" ...
            #include "classname.h" 
    
            void $::Method() { }  
    
            //i was using also 
            #define $$ BaseClass 
            //with single inheritance  than i can do this: 
    
            void $::Method() 
            { 
            $$::Method(); //call base class method 
            } 
    
            //but with a typedef defined into class like this it's better to do this: 
            class Derived : Base 
            { 
            typedef Base $$;  
    
        }
    
    0 讨论(0)
提交回复
热议问题