Tell me how you compile in Eclipse?

I started writing one project, and ran into the following (I attach the code below)

Property.h

#ifndef PROPERTY #define PROPERTY #include <stdlib.h> #include<functional> using namespace std; namespace Extentions { // Property types class ReadOnly; class WriteOnly; class ReadWrite; // Property structure template<typename T_param, typename Access> class Property; // Property getter template<typename T_param> class Property<T_param, ReadOnly> { protected: T_param *_param; public: Property(T_param *param) : _param(param){}; operator T_param(); }; template<typename T_param> Property<T_param, ReadOnly>::operator T_param() { return *_param; } // Property setter template<typename T_param> class Property<T_param, WriteOnly> { protected: T_param *_param; function<bool(T_param)> checkParam; public: Property(T_param *param, function<bool(T_param)> paramChecker) : _param(param), checkParam(paramChecker){}; void operator =(T_param param); }; template<typename T_param> void Property<T_param, WriteOnly>::operator =(T_param param) { if(checkParam(param)) *_param = param; }; // Property setter and getter template<typename T_param> class Property<T_param, ReadWrite> { protected: T_param *_param; function<bool(T_param)> checkParam; public: Property(T_param *param, function<bool(T_param)> paramChecker) : _param(param), checkParam(paramChecker){}; Property(T_param *param) : _param(param), checkParam([](T_param){ return true;}){}; void operator =(T_param param); operator T_param(); }; template<typename T_param> void Property<T_param, ReadWrite>::operator =(T_param param) { if(checkParam(param)) *_param = param; }; template<typename T_param> Property<T_param, ReadWrite>::operator T_param() { return *_param; } } #endif 

This is my header file. And below is a test project:

 #include <iostream> #include "../headders/Property.h" using namespace std; using namespace Extentions; class MyTestClass { private: int i = 5; public: Property<int, ReadOnly> p_R; Property<int, WriteOnly>p_W; Property<int, ReadWrite> p_RW; MyTestClass() : p_R(&i), p_W(&i,[](int data){return data > 10;}), p_RW(&i){} }; int main() { MyTestClass cl; cl.p_RW = 18; int j = cl.p_RW; cout << j << endl; return 0; } 

When I compile everything as it is now - everything compiles, but when I try to render the implementation of methods in Property.cpp (that is, I just transfer the implementation that is now declared in the header file - to the file with the .cpp extension) - I get an error. Moreover, ecleapse prescribes how much I understand everything in the make file as needed, the error is that it tries to compile it with an explicitly defined template where T_param = int. those. if I transfer the entire implementation as it is now from the header file - to the file "Prorerty.cpp" - an error occurs, but if I'm not changing the code in the same Property.cpp, I explicitly implement the T_param template purely for int, then the code is compiled and executed correctly.

Accordingly, the question is how do you compile the code in ecleapse? Do you write your own make files or do you trust autogeneration? I am new to Linux programming, and for this I now would like to entrust the creation of a make file to the development environment, the more I will need to further debug the project in ecleapse and would like the environment itself to compile everything as it needs.

Tell me how to solve this situation?

It also interests (as a supplement to the question) whether it is possible to compile on own make files inside the environment (ie if I still want to feed my MakeFile to Ecleapse, then how can I do this?)

1 answer 1

Templates generate code only when you use this template in a program with specific parameters. You cannot compile a module containing just a class template. But if you know in advance that a particular type will be used, you can render it in Property.cpp (which you actually did for an int). But then anything but int will lead to errors, so I don’t see the point in this case.

Now about eclipse (as if you turned the mind into ecleapse, I don’t attach: D), just google "creating your makefile eclipse" and get an illustrated little article on help.eclipce

  • Thank, leave in the head then. - JamesBondCaesar