السلام عليكم ورحمة الله وبركاته
أحبائي مرحباً بكم، لدي مشكلة في إعداد برنامج يتعلق الأمر في كود الmain
لدي class of array list وفيه template أريد أن أستضيف من خلاله
struct car
{
int model;
long number;
string brand;
double mialage;
double price;
};وهذا هو الصف:
template <class T>
class ArrayListType
{
public:
void insert(const T & item);
void remove(const T & item);
void retreive(int loc, T & item);
void printAll();
void printOne();
bool search(const T & item);
bool CheckSameBrand(const T & item);
ArrayListType();
~ArrayListType();
private:
int maxsize;
int length;
T *list;
};جميل :lol: .. انزين أنا كتبت الfunctions بس لما أروح على main functin
وأريد أعمل insert كالتالي يظهر لي خطأ
car c; cout << "please Input the Information now:" << endl; cout << "car model: "; cin >> c.model; cout << "car number: "; cin >> c.number; cout << "car brand: "; cin >> c.brand; cout << "car mialage: "; cin >> c.mialage; cout << "car price: "; cin >> c.price; ArrayListType<car> add; add.insert(c);
الخطأ إلي يظهر هو: :wacko:
error C2784: 'bool __cdecl std::operator ==(const class std::basic_string<_E,_Tr,_A> &,const _E *)' : could not deduce template argument for 'const class std::basic_string <_E,_Tr,_A> &' from 'struct car' while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' error C2784: 'bool __cdecl std::operator ==(const _E *,const class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'const *' from 'struct car' while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' error C2784: 'bool __cdecl std::operator ==(const class std::basic_string<_E,_Tr,_A> &,const class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument fo r 'const class std::basic_string<_E,_Tr,_A> &' from 'struct car' while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' error C2784: 'bool __cdecl std::operator ==(const class std::allocator<_Ty> &,const class std::allocator<_U> &)' : could not deduce template argument for 'const class std: :allocator<_Ty> &' from 'struct car' while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' error C2784: 'bool __cdecl std::operator ==(const class std::istreambuf_iterator<_E,_Tr> &,const class std::istreambuf_iterator<_E,_Tr> &)' : could not deduce template arg ument for 'const class std::istreambuf_iterator<_E,_Tr> &' from 'struct car' while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' error C2784: 'bool __cdecl std::operator ==(const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not d educe template argument for 'const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &' from 'struct car' c:\program files\microsoft visual studio\vc98\include\xstring(111) : while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' error C2784: 'bool __cdecl std::operator ==(const struct std::pair<_T1,_T2> &,const struct std::pair<_T1,_T2> &)' : could not deduce template argument for 'const struct st d::pair<_T1,_T2> &' from 'struct car' c while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' error C2676: binary '==' : 'struct car' does not define this operator or a conversion to a type acceptable to the predefined operator while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' warning C4305: 'return' : truncation from 'const int' to 'bool' while compiling class-template member function 'bool __thiscall ArrayListType<struct car>::search(const struct car &)' Error executing cl.exe. assginment_2.obj - 8 error(s), 2 warning(s)
فأرجو المساعدة يا أخوان ما هي الطريقة الصحيحة لتخزين الstruct داخل الـ list
وكيف يمكن للإتصال بالفنكشن من دون حدوث هذه الأخطاء ؟!
شاكر لكم ومقدر :wub:
