1
In c++14 It works well
//ar.h
#ifndef AR_H
#define AR_H
template<class T>
class ar {
public:
ar();
~ar();
int insertD(T value);
private:
protected:
};
#endif //AR_H
..
//ar.cpp
#include "ar.h"
template<class T>
int ar<T>::insertD(T value){
int testInsert = -1;
//..
//..
return testInsert;
}
//main.cpp
#include "ar.h"
#include "ar.cpp"
int main(int argc, char **argv){
arr<int> arrD;
arrD.insertD(1);//test
return 0;
}
This is the right way to do this in C++14, only include, ar.cpp only in main.cpp?
UPDATE
After a long time...I decided to change my GNU and test in another OS, my surprise was that both Example 1 and 3 which are the same, they work well in both C ++ 14 and C ++ 11, maybe it's a bug in my compiler.
https://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_3.html
-pedantic Valid ISO C and ISO C++ programs should compile properly with or without this option (though a rare few will require -ansi or a -std option specifying the required version of ISO C). However, without this option, certain GNU extensions and traditional C and C++ features are supported as well. With this option, they are rejected.
-pedantic: used in conjunction with -ansi, this tells the compiler to be adhere strictly to the ANSI standard, rejecting any code which is not compliant.
- c ++ 14 without pedantic works well
- c ++ 14 with pedantic works well
- c ++ 11 without pedantic, does not work
- c ++ 11 with pedantic works well