Yazılım
Seçkin Üye
Template olmayan sınıflarda header ve kaynak kod olmak üzere 2 dosyadan oluşur. Fakat template’larda bu çalışmaz.
Dizi.h
#ifndef DIZI_H
#define DIZI_H
#include <assert.h>//assert() için
template <class T>
class Dizi
{
private:
int m_uzunluk;
T* m_veri;
public:
Dizi(){
m_uzunluk = 0;
m_veri = nullptr;
}
Dizi(int uzunluk){
assert(uzunluk > 0);
m_veri = new T[uzunluk];
m_uzunluk = uzunluk;
}
~Dizi(){
delete[] m_veri;
}
void Sil(){
delete[] m_veri;
m_veri = nullptr;
m_uzunluk = 0;
}
T& operator[](int index){
assert(index >=0 && index < m_uzunluk);
return m_veri[index];
}
int getUzunluk();
};
#endif
Dizi.cpp
#include "Array.h"
template <typename T>
int Array<T>::getLength() {return m_length;}
Dizi.h
#ifndef DIZI_H
#define DIZI_H
#include <assert.h>//assert() için
template <class T>
class Dizi
{
private:
int m_uzunluk;
T* m_veri;
public:
Dizi(){
m_uzunluk = 0;
m_veri = nullptr;
}
Dizi(int uzunluk){
assert(uzunluk > 0);
m_veri = new T[uzunluk];
m_uzunluk = uzunluk;
}
~Dizi(){
delete[] m_veri;
}
void Sil(){
delete[] m_veri;
m_veri = nullptr;
m_uzunluk = 0;
}
T& operator[](int index){
assert(index >=0 && index < m_uzunluk);
return m_veri[index];
}
int getUzunluk();
};
#endif
#include "Array.h"
template <typename T>
int Array<T>::getLength() {return m_length;}