Home  >  Q&A  >  body text

vs2013怎么快速生成C++类成员变量的get,set函数, 类似eclipse的功能

vs2013怎么快速生成类成员变量的get,set函数, 类似eclipse的功能

PHPzPHPz2715 days ago729

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 11:58:42

    You can check this out at http://my.oschina.net/fjxy/blog/72106

    reply
    0
  • 阿神

    阿神2017-04-17 11:58:42

    I remember that C# in vs uses ctr+r+e to quickly generate attributes for fields. As for c++, it seems that the syntax is not necessary.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:58:42

    I have not found this function.
    It is possible to use Qt Creator, move the cursor to the member variable, and then use the shortcut Alt + Enter and the option will appear.
    If there are many member variables to be defined in VS, you can use the class wizard function to create a class.
    If you don’t mind it, you can use the following macro definition

    #ifndef MEM_GET_SET
    #define MEM_GET_SET(member,member_type) \
        member_type get_##member(){return member;}
        void set_member(member_type value){ this->member = value;}

    endif

    Use as follows

    class A
    {
    public:
        MEM_GET_SET(a,int)
    private:
    int a;
    };

    reply
    0
  • Cancelreply