Fwd: I use g++(gcc) 3.4.2 in win32 platform, and I can't compile my little program....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am a student and I use dev-c++ with g++ (GCC) 3.4.2 (mingw-special)to compile my program. When I compile my program, I get some errormessage like this:
=====================================================In member function `MyType* Stack<MyType>::Delete(MyType&)':    108 there are no arguments to `IsEmpty' that depend on a templateparameter, so a declaration of `IsEmpty' must   be available    108 (if you use `-fpermissive', G++ will accept your code, butallowing the use of an undeclared name is deprecated)    108 there are no arguments to `Empty' that depend on a templateparameter, so a declaration of `Empty' must be available    109 `array' undeclared (first use this function)        (Each undeclared identifier is reported only once for eachfunction it appears in.)    109 `top' undeclared (first use this function)=====================================================
and I list my code below:=====================================================#include <iostream>const int DefaultSize = 20;using namespace std;
template <class MyType>class Bag{public:       Bag(int MaxSize=DefaultSize);  //建構子       virtual ~Bag(); //解構子
      virtual void Add(MyType); // 插入element到bag裡面       virtual MyType* Delete(MyType&); //從bag刪除element
      virtual bool IsFull(); //當bag是滿的傳回true,反之則為false       virtual bool IsEmpty(); // 當bag是空的傳回true,反之則為falseprotected:       virtual void Full(); //bag是滿的就會執行       virtual void Empty(); // bag是空的就會執行
      MyType *array;       int MaxSize; //array的大小       int top; //在array中含括element的最高位置};
template <class MyType>class Stack : public Bag<MyType>{    public:       Stack(int MaxSize=DefaultSize); //建構子       ~Stack(); //解構子       MyType* Delete(MyType&);};
int main(void){       Bag <int> b(5); // 利用Bag的建構子建立一個大小為5的array
      Stack <int> s(5); //利用Stack的建構子建立一個大小為5的array
      b.Add(1);b.Add(2);b.Add(3);b.Add(4);b.Add(5);       //用Bag::Add 呼叫 Bag::Full,Bag::IsFull       s.Add(7);s.Add(8);s.Add(9);s.Add(10);s.Add(11);
      int x;       b.Delete(x);       cout << "x = " << x << endl;       s.Delete(x);       cout << "x = " << x << endl;       //system("pause");       return 0;}
template<class MyType>Bag<MyType>::Bag(int MaxBagSize):MaxSize(MaxBagSize){       array = new MyType[MaxSize];top=-1;}
template<class MyType>Bag<MyType>::~Bag(){delete [] array ;}
template<class MyType>inline bool Bag<MyType>::IsEmpty(){       if(top==-1) return true ; else return false;}
template<class MyType>inline bool Bag<MyType>::IsFull(){       if(top==MaxSize-1) return true ; else return false;}
template<class MyType>inline void Bag<MyType>::Full(){       cerr << "DATA STRUCTURE IS FULL" << endl;}
template<class MyType>inline void Bag<MyType>::Empty(){       cerr << "DATA STRUCTURE IS Empty" << endl;}
template<class MyType>void Bag<MyType>::Add(const MyType x){       if(IsFull())Full();else array[++top]=x;}
template<class MyType>MyType* Bag<MyType>::Delete(MyType& x){       if(IsEmpty()){Empty(); return 0;}       int deletePos = top/2 ;       x=array[deletePos];       for (int index = deletePos ; index<top ; index++)         array[index]= array[index+1];       top--;return &x;}
template<class MyType>Stack<MyType>::Stack(int MaxStackSize):Bag<MyType>(MaxStackSize){}//constructor for stack calls constructor for bag
template<class MyType>Stack<MyType>::~Stack(){} //用來確定array被刪除
template<class MyType>MyType* Stack<MyType>::Delete(MyType& x){       if(IsEmpty()){Empty();return 0 ; }       x=array[top--];       return &x;}=====================================================
The class Stack  is derived from the class Bag, and all the datamembers are inherited from Bag.
Can any one help?
RegardsAuxo

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux