السلام عليكم ورحمة الله وبركاته
ان شاء الله الكل بخير
في stack انشات ملف الهيدر و cpp والملف التنفيذي
مرتبة كالاتي
هذا الملف الهيدر
template < class itemtype >
class stacktem {
public :
stcktem ( ) ;
stacktem ( int max ) ;
~stacktem ( ) ;
bool isfull ( ) ;
void push ( int itemtype ) ;
void pop ( int & itemtype ) ;
private :
int top ;
int maxstack ;
itemtype * items ;
};هذا ملف cpp
template <class itemtype>
stacktem <itemtype> :: stacktem ( )
{
maxstack = 500 ;
top = -1 ;
items = new itemtype[500] ;
}
template < class itemtype >
stacktem < itemtype > :: stacktem ( int max )
{
maxstack = max ;
tem = -1 ;
items = new itemtype[max] ;
}
template < class itemtype >
stacktem < itemtype > :: ~stacktem ( )
{
delete [] items ;
}
template<class itemtype>
bool stacktem <itemtype>::isfull( )
{
return (top == maxstack - 1)
}
template<class itemtype>
void stacktem <itemtype>::push ( int newitem )
{
top++;
items[top] = newItem;
}
template<class itemtype>
void stacktem <itemtype>::pop ( int & iitem )
{
items[top] = iitem ;
top--
}وهذا الملف التنفيذي
# include < iostream >
using namespace std ;
int main ( )
{
stacktem R ;
R.stacktem ( ) ;
}تظهر لي الاخطاء هنا لا اعرف ما هي لاني لا أرى خطا منطقي
Error 1 error C2143: syntax error : missing ';' before '<' c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 3
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 3
Error 3 error C2988: unrecognizable template declaration/definition c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 3
Error 4 error C2059: syntax error : '<' c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 3
Error 5 error C2143: syntax error : missing ';' before '{' c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 15
Error 6 error C2447: '{' : missing function header (old-style formal list?) c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 15
Error 7 error C2143: syntax error : missing ';' before '<' c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 26
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 26
Error 9 error C2086: 'int stacktem' : redefinition c:\users\tech\documents\visual studio 2005\projects\notes\stacktem\stacktem\stacktem.cpp 26هذا بعض من الاخطاء :S :S
ومالغرض الاساسي من template
قرات في الكتب الفرق بينها وبين الكلاس العادي انها نستخدم نفس الملفات هل هذا صحيح
اتمنى القى الاجابة لديكم وشكرا مقدما لافضل منتدى عربي :)
