c++ - How to make CLion insert generated code.... in .cpp files -


generating code in clion result in having methods implemented in header files, i've been taught should go in .cpp files, how can change behavior , possible ?

example :

in project containing main.cpp , test class (test.hpp, , test.cpp).

the cmake file follow:

cmake_minimum_required(version 3.3) project(testclion)  set(cmake_cxx_flags "${cmake_cxx_flags} -std=c++11")  set(source_files main.cpp                 test.cpp                 test.hpp) add_executable(testclion ${source_files}) 

(note default file provided clion, haven't changed anything)

test.hpp

#ifndef testclion_test_hpp #define testclion_test_hpp  class test {  protected:   int test; };   #endif //testclion_test_hpp 

test.cpp

#include "test.hpp" 

pressing alt + insert , generating getters/setters while being in test.hpp or test.cpp changes test.hpp:

test.hpp

#ifndef testclion_test_hpp #define testclion_test_hpp  class test {   public:   int gettest() const   {     return test;   }   void settest(int test)   {     test::test = test;   }  protected:   int test; };   #endif //testclion_test_hpp 

ok, have actual solution you. had same problem alt + enter , auto generate per method. can work around via using alt + insert. brings generation menu in clion. here select generate definitions bring menu can either select definitions or select select few want generate.

clion smart enough know if you've already generated definition don't have worry duplicate definitions here. i've found qt classes have meta object compiler overrides show here, make sure not select when creating definitions, normal use cases selecting every element in generate definitions list generate things you've defined in header.

note can right click on class name , go generate... , given same options.

edit: note if want behavior of original author, can select "generate in place" option once generate definitions function selection screen


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -