Need help

Hello!
I am a beginner in c++ programming, and I need some help.
I have a homework on the university. I have to write a generic array, and I got some with it.
First here is the array:

#include<memory.h>

template <typename T, int meret>
class Halmaz {

public:
T tomb[meret];
const int m;
Halmaz():m(meret){memset(tomb,0,meret*sizeof(T));}
void tvissza(Halmaz &v);
void rendez(T *t);
T& operator[](int idx);
bool operator<=(Halmaz& a);
Halmaz& operator-(Halmaz & hal);
Halmaz& metszet(Halmaz &egyik, Halmaz &masik);
Halmaz& unio(Halmaz &egyik ,Halmaz &masik);
~Halmaz(){delete[] tomb;}
};

Here is the operator[], which doesn't work in the try block:

template<typename T, int meret>
T& Halmaz<T,meret>::operator[](int idx)throw(const char*)
{
if(idx<0 || idx>=m)
throw ("Indexhiba!");
else
return tomb[idx];
}

And here is the testing part:

#include<iostream>
#include<exception>
#include<stdlib.h>
#include"sablon.h"

using namespace std;


int main()
{
Halmaz<int,20> t;
try{
t.tomb[2]=3;
t.tomb[4]=6668;
t.tomb[-1]=7;
for(int i=0; i<t.m; ++i)
cout<<t.tomb[i]<<'\t';

}
catch(const char *s){
cout<<s<<endl;
}
}

Or maybe there is some problem with including, because I always get the message : "rendez" identifer not found
closed account (oN3AqMoL)
You didnt include iostream in the n on testing part, you still need to........ lol
(Btw with your code highlight it and select the <> under format. It makes the code much easier to read.)
Last edited on
Topic archived. No new replies allowed.