smart Pointer error?

Hi there,

I wrote a smart pointer class
but I can not write more.
Could you share with me your knowledge of C++.

Thanks for reading!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
template<class T>
class smartPTR{
	T *mp;
	T *Array;
	int size;
public:
	smartPTR(T *p):mp(p){}
	smartPTR(T *p ,T *v ,int s)
	{ 
		mp = &p[0];
		Array = v;
		size = s;
	}

	~smartPTR()
	{
		delete mp;
	}
	T &operator*()
	{
		return *mp;
	}
	T *operator->()
	{
		return mp;
	}

	T &operator[](int i)
	{
		return mp[i];
	}

	smartPTR &operator++()
	{
		this->mp++;
		return *this;
	}
	smartPTR operator++(int);
	smartPTR &operator--();
	smartPTR operator--(int);

};


class firix{
	int x;
public:
	firix(int xx = 0):x(xx){}
	void display()const
	{
		cout << "x :" <<  x  << endl;

	}


};


int main()
{
	smartPTR<firix> ptr = new firix[11];

	ptr->display();


	++ptr;
	
	return 0;
}



Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
template<class T>
class smartPTR{
	T *mp;
	T *Array;
	int size;
public:
	smartPTR(T *p = 0):mp(p){}
	smartPTR(T *p ,T *v ,int s)
	{ 
		mp = &p[0];
		Array = v;
		size = s;
	}

	smartPTR<T> &operator=(smartPTR<T> &r)
	{
		if (this != &r){
			delete mp;
			mp = r.mp;
			r.mp = NULL;
		}

		return *this;
	}

	~smartPTR()
	{
		delete mp;
	}
	T &operator*()
	{
		return *mp;
	}
	T *operator->()
	{
		return mp;
	}

	T &operator[](int i)
	{
		return mp[i];
	}

	smartPTR &operator++()
	{
		this->mp++;
		return *this;
	}
	smartPTR operator++(int);
	smartPTR &operator--();
	smartPTR operator--(int);

};


class firix{
	int x;
public:
	firix(int xx = 0):x(xx){}
	void display()const
	{
		cout << "x :" <<  x  << endl;

	}


};
Topic archived. No new replies allowed.