* Fwd: I use g++(gcc) 3.4.2 in win32 platform, and I can't compile my little program....
[not found] ` <a4a3851a0605140441l27c4eb60i296b3c9d9e5ba5ec@mail.gmail.com>
@ 2006-05-14 14:23 ` 阿保
0 siblings, 0 replies; only message in thread
From: 阿保 @ 2006-05-14 14:23 UTC (permalink / raw)
To: gcc-help
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 error
message like this:
=====================================================
In member function `MyType* Stack<MyType>::Delete(MyType&)':
108 there are no arguments to `IsEmpty' that depend on a template
parameter, so a declaration of `IsEmpty' must be available
108 (if you use `-fpermissive', G++ will accept your code, but
allowing the use of an undeclared name is deprecated)
108 there are no arguments to `Empty' that depend on a template
parameter, so a declaration of `Empty' must be available
109 `array' undeclared (first use this function)
(Each undeclared identifier is reported only once for each
function 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,反之則為false
protected:
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 data
members are inherited from Bag.
Can any one help?
Regards
Auxo
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-05-14 14:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <a4a3851a0605140432y27756e9eh38658a2ccf477c7@mail.gmail.com>
[not found] ` <a4a3851a0605140434p6c0a9c9eq573196923b76b162@mail.gmail.com>
[not found] ` <a4a3851a0605140441l27c4eb60i296b3c9d9e5ba5ec@mail.gmail.com>
2006-05-14 14:23 ` Fwd: I use g++(gcc) 3.4.2 in win32 platform, and I can't compile my little program 阿保
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).