c++ operator overloading

Marios K. marios_hellas_23 at yahoo.gr
Thu Feb 24 16:01:43 EET 2005


Ti la8os yparxei edo.


ARXEIO mvector.h
////////////////////////////////////////////////////////////////////
class MVECTOR
{

private:
int size;
int *A;

public:

MVECTOR(int siz)
	{
	size=siz;
	A=new int[size];A=A+1;
	}

int  &operator [] (int i) {
if (i>size) std::cout<<"Index exceeds matrix dimensions."<<std::endl;}

};
////////////////////////////////////////////////////////////////////

ARXEIO main.cpp

#include <iostream>
#include <new>
#include <memory>

#include "mvector.h"

int main()
{
MVECTOR aaa(10);

std::cout<<"Start"<<std::endl;


aaa[12]=3;


std::cout<<"END";

}

Oriste to output

marios at base-06:~/Projects/test_c> ./a.out
Start
Index exceeds matrix dimensions.
Segmentation fault


An allakso ton aaa[12] se aaa[2] 
marios at base-06:~/Projects/test_c> ./a.out
Start
Segmentation fault


Ti paizei?

-- 
Marios K. <marios_hellas_23 at yahoo.gr>






More information about the Linux-greek-users mailing list