Код: Выделить всё
template class Pair{};
// no definitions in the original template class
typedef std::valarray ArrayInt;
typedef Pair PairArray;
template class Pair{
protected:
ArrayInt arr1;
ArrayInt arr2;
public:
Pair(const int n, const int ar1[], const int ar2[]);
// n is the number of elements in both valarrays
explicit Pair(const int n);
virtual ~Pair(){}
};
Код: Выделить всё
Pair::Pair(const int n, const int ar1[], const int ar2[])
: arr1(ar1, n), arr2(ar, n){}
Pair::Pair(const int n) : arr1(n), arr2(n){
for(int i = 0;i < n;i++){
years[i] = bottles[i] = 0;
}
}
< /code>
Однако компилятор жаловался во время компиляции: < /p>
In function `void std::__valarray_destroy_elements(int*, int*)':
multiple definition of `Pair::Pair(int, int const*, int const*)'
test.tpp:2: first defined here
ld returned 1 exit status
< /code>
Я попытался сделать два определения встроено, и программа компилируется. Почему встроенные дополнения здесь необходимы? Я знаю, что мне не нужен встроенный (PS: Этот вопрос может напоминать более общие, заданные ранее, но я не получил никакой подсказки после прочтения ответов. Заранее!) < /P>
Подробнее здесь: https://stackoverflow.com/questions/794 ... ialization
Мобильная версия