Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   Шаблоны классов (https://forum.antichat.xyz/showthread.php?t=94091)

A-Spt_N(o) 29.11.2008 18:35

Шаблоны классов
 
Готовлю защиту по лабораторной работе...
не могу понять в чем ошибка:
Код:

#include <assert.h>
#include <iostream>
#include "template.h"

using namespace std;

// ОШИБКА В ЭТИХ СТРОЧКАХ!!!
template class ARRAY<int, int, int>;
template class ARRAY<double, int, int>;

// Конструктор
template <class Type, int low, int hight>
ARRAY<Type, low, hight>::ARRAY()
{        // Забиваем массив нулями
        for( int i = low; i <= hight; i++ ) { arr[i] = 0; }
}

// Деструктор
template <class Type, int low, int hight>
ARRAY<Type, low, hight>::~ARRAY(){}

// Поместить елемент в массив
template <class Type, int low, int hight>
void ARRAY<Type, low, hight>::PUT(Type num, int pos)
{       
        if( low <= pos && pos <= hight ) { arr[pos] = num; }
        else cout << "ERROR POSITION!!!" << endl;
}

// Удалить елемент из массива
template <class Type, int low, int hight>
void ARRAY<Type, low, hight>::PUSH( int pos )
{       
        if( low <= pos && pos <= hight ) { arr[pos] = 0; }
        else cout << "ERROR POSITION!!!" << endl;
}

// Печать массива
template <class Type, int low, int hight>
void ARRAY<Type, low, hight>::print() const
{
        cout << "Array: \t";
        // Выводим массив
        for (int i = low; i < hight; i++) { cout << "\t" << arr[i] << " "; }

        cout << endl << "index_x: " << x        // Вывод нижней границы
            << endl << "index_y: " << y        // Вывод верхней границы
                << endl << endl;
}

// Перегруженная операция индексации
template <class Type, int low, int hight>
Type &ARRAY<Type, low, hight>::operator[]( int subscript )
{
        // Проверка ошибочного выхода индекса из диапозона
        assert( low <= subscript && subscript < hight );

        return arr[subscript];
}


A-Spt_N(o) 29.11.2008 19:26

Неужели тут нет людей разбирающихся в С++??

Shaitan-Devil 30.11.2008 10:30

В чем цель программы?

A-Spt_N(o) 30.11.2008 15:32

та какая разница в чем суть программы... мне надо исправить те две строчки объявления шаблона...

Изначально было

template class ARRAY<int>;
template class ARRAY<double>;

и все нормально работала... лабораторку я показал все отлично. на защиту меня попросили немного переделать программку


Время: 14:18