what is the wrong here ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template<class T>
	supermarket& supermarket<T>::operator=(supermarket& b)
	{
		*name_of_supermarket=*(b.name_of_supermarket);
		*area=*(b.area);

			for(int i=0;i<size;i++)
			{Array[i]=a.Array[i];}

		for(int i=0;i<size;i++)
		{Array_ofgeneric[i]=a.Array_ofgeneric[i];}


		return *this;
	}



it give me error like this
1
2
3
4
5
6
7
8
1>c:\users\odai\documents\visual studio 2010\projects\hw4\hw4\main.cpp(83): error C2955: 'supermarket' : use of class template requires template argument list
1>          c:\users\odai\documents\visual studio 2010\projects\hw4\hw4\main.cpp(9) : see declaration of 'supermarket'
1>c:\users\odai\documents\visual studio 2010\projects\hw4\hw4\main.cpp(96): error C2244: 'supermarket<T>::operator =' : unable to match function definition to an existing declaration
1>          c:\users\odai\documents\visual studio 2010\projects\hw4\hw4\main.cpp(15) : see declaration of 'supermarket<T>::operator ='
1>          definition
1>          'supermarket supermarket<T>::operator =(supermarket<T> &)'
1>          existing declarations
1>          'supermarket<T> &supermarket<T>::operator =(supermarket<T> &)'
existing declarations
'supermarket<T> &supermarket<T>::operator =(supermarket<T> &)'

supermarket is not a typename. supermarket<T> is.
so ?! what should i do ? the wrong is in this function only ! when i write it like a comment my program working !!
no answer ?!
all code is look like

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef SUPERMARKET_H
#define SUPERMARKET_H
#include<string>
#include<iostream>
using namespace std;

template<class T>
class supermarket
{
public:

	supermarket(string,int,string[],int,T[]);
	~supermarket();
	supermarket(supermarket&);
	supermarket& operator=(supermarket&);


	void setname_of_supermarket(int);
	void setarea(int);
	


	int getname_of_supermarket();
	int getarea();
	
	void print();

private:
	string *name_of_supermarket;
	int *area;
	string *Array[];
	int size;
	T *Array_ofgeneric[] ;
	

};
#endif


template<class T>
supermarket<T>::supermarket(string a,int b,string c[],int s,T x[])
{
	name_of_supermarket=new string(a);
	area=new int(b);
	size=s;

	Array=new string c[s];
	for(int i=0;i<s;i++)
		Array[i]=c[i];

	Array_ofgeneric=new T x[s];
	for(int i=0;i<s;i++)
		Array_ofgeneric[i]=x[i];


}
template<class T>
	supermarket<T>::~supermarket()
	{
		delete name_of_supermarket;
		name_of_supermarket=0;
		delete area;
		area=0;
		delete[] Array;
		Array=0;
		delete[] Array_ofgeneric;
		Array_ofgeneric=0;
	}
	template<class T>
	supermarket<T>::supermarket(supermarket& a)
	{
		name_of_supermarket=new string(*(a.name_of_supermarket));
		area=new int(*(a.area));
		Array=new string[a.size];
		for(int i=0;i<size;i++)
			Array[i]=a.Array[i];
		Array_ofgeneric=new T[a.size];
		for(int i=0;i<size;i++)
			Array_ofgeneric[i]=a.Array_ofgeneric[i];
	}

	/*template<class T>
	supermarket& supermarket<T>::operator=(supermarket& b)
	{
		*name_of_supermarket=*(b.name_of_supermarket);
		*area=*(b.area);

			for(int i=0;i<size;i++)
			{Array[i]=a.Array[i];}

		for(int i=0;i<size;i++)
		{Array_ofgeneric[i]=a.Array_ofgeneric[i];}


		return supermarket;
	}*/

	template<class T>
	void supermarket<T>::setname_of_supermarket(int a)
	{
		*name_of_supermarket=a;
	}
	template<class T>
	void supermarket<T>::setarea(int b)
	{
		*area=b;
	}
	

	template<class T>
	int supermarket<T>::getname_of_supermarket()
	{
		return *name;
	}
	template<class T>
	int supermarket<T>::getarea()
	{
		return *area;
	}
	template<class T>
	void supermarket<T>::print()
	{
		cout<<"the name is "<<name<<endl;
		cout<<"the area is "<<area<<endl;
		cout<<"the Array is "<<Array<<endl;
		cout<<"the array of geadd is "<<Array_ofgeneric;

	}




	void main()

	{
	
		
		

	}




what should i write in main !! and what is the wrong in copy constructor ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template <class T>
class Foo {
...
  Foo<T> & operator= ( Foo<T> const & F );
...
};

template <class T>
Foo<T> & Foo<T>::operator= ( Foo<T> const & F )
{
  if ( this != &F )
    {
      // copy members
    }
  return *this;
}

ok i solved it but what about main !!

when i write

supermarket<int> c("ssss",111,"ddd",111,445);//fore example

it give me an error in "ssss" why ? it's not a template !!
Topic archived. No new replies allowed.