|
藍森林 http://www.lslnet.com 2006年6月6日 10:18
aix下的c++(template)問題(向高手請教。。有難度)
我在aix下用 cc(c++)編譯一個lcjsmain.C
報錯:
"dynamic.h", line 235.14: 1540-252: (W) The destructor for "int" does not exist.
The call is ignored.
"dynamic.h", line 53.21: 1540-207: (I) The previous message applies to the definition of template "DynamicArray<int>;::FreeData()".
ld: 0711-317 ERROR: Undefined symbol: .operator delete(void*)
ld: 0711-317 ERROR: Undefined symbol: .__Throw
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
lcjsmain.C指包含了dynamic.h,沒有其他的內容
dynamic.h看後面
235.14: 指的是 dynamic.h倒數 第八行 p->;~T();
#if !defined(DYNAMIC_H) // dynamic array
#define DYNAMIC_H
#include <stdlib.h>; // malloc, free
class DynArrayException
{};
class DynArrayOutOfRange : public DynArrayException
{
public:
DynArrayOutOfRange(int index, int count) : m_Index(index),
m_Count(count)
{}
int m_Index;
int m_Count;
};
class DynArrayNullData : public DynArrayException
{};
template <class T>; class DynamicArray;
template <class T>; inline int
GetDimensions(const DynamicArray<T>;& t) { return t.DimCount();}
template <class T>; inline int
GetDimensions(const T&) { return 0;}
template<class T>; class DynamicArray
{
public:
DynamicArray();
~DynamicArray();
DynamicArray(const DynamicArray<T>;& src);
T& operator[](int index);
T operator[](int index) const;
DynamicArray<T>; Copy() const;
void Copy(DynamicArray<T>; &dst) const;
DynamicArray<T>; CopyRange(int startIndex, int count) const;
void CopyRange(DynamicArray<T>; &dst, int startIndex, int count) const;
int get_high() const;
int get_low() const;
int get_length() const;
void set_length(int l);
#if defined(DEBUG)
int get_refCount() const;
#endif
static int DimCount()
{
return 1 + GetDimensions(*((T*)(0)));
}
protected:
void IncRefCount();
void DecRefCount();
static T* AllocData(int count);
void SetData(T* t);
void FreeData();
private:
T* Data;
};
inline void* operator new(size_t size, char *p)
{
return p;
}
template <class T>;
DynamicArray<T>;::DynamicArray() : Data(0)
{}
template <class T>;
DynamicArray<T>;::~DynamicArray()
{
DecRefCount();
Data = 0;
}
template <class T>;
DynamicArray<T>;::DynamicArray(const DynamicArray<T>;& src) : Data(src.Data)
{
IncRefCount();
}
template <class T>; T&
DynamicArray<T>;::operator[](int index)
{
if (index < 0 || index >;= this->;get_length() )
throw DynArrayOutOfRange(index, this->;get_length() );
if (!Data)
throw DynArrayNullData();
return *(Data + index);
}
template <class T>; T
DynamicArray<T>;::operator[](int index) const
{
if (index < 0 || index >;= this->;get_length() )
throw DynArrayOutOfRange(index, this->;get_length() );
if (!Data)
throw DynArrayNullData();
return *(Data + index);
}
template <class T>; DynamicArray<T>;
DynamicArray<T>;::Copy() const
{
DynamicArray<T>; cpy;
Copy(cpy);
return cpy;
}
template <class T>; void
DynamicArray<T>;::Copy(DynamicArray<T>;& dst) const
{
int l = (*this).get_length();
if (dst.get_length() != l)
dst.set_length(l) ;
for (int i=0; i<l; i++)
dst[i] = (*this)[i];
}
template <class T>; DynamicArray<T>;
DynamicArray<T>;::CopyRange(int startIndex, int count) const
{
DynamicArray<T>; cpy;
CopyRange(cpy, startIndex, count);
return cpy;
}
template <class T>; void
DynamicArray<T>;::CopyRange(DynamicArray<T>;& dst, int startIndex, int count) const
{
if (dst.get_length() != count)
dst.set_length( count ) ;
for (int i=0; i<count; i++)
dst[i] = (*this)[startIndex+i];
}
template <class T>; int
DynamicArray<T>;::get_high() const
{
return Data ? get_length()-1 : 0;
}
template <class T>; int
DynamicArray<T>;::get_low() const
{
return 0;
}
template <class T>; int
DynamicArray<T>;::get_length() const
{
int *p_i = (int*)Data;
return Data ? *(p_i-1) : 0;
}
template <class T>; void
DynamicArray<T>;::set_length(int l)
{
T* p = AllocData(l);
if (p)
{
int copyLen = (*this).get_length();
if (l < copyLen)
copyLen = l;
while (copyLen-- >; 0)
p[copyLen] = (*this)[copyLen];
}
SetData(p);
}
#if defined(DEBUG)
template <class T>; int
DynamicArray<T>;::get_refCount() const
{
int* p_i = (int*)Data;
return Data ? *(p_i-2) : 0;
}
#endif
template <class T>; void
DynamicArray<T>;::IncRefCount()
{
if (Data)
{
int* p_i = (int*)Data;
int &refcount = *(p_i-2);
refcount++;
}
}
template <class T>; void
DynamicArray<T>;::DecRefCount()
{
if (Data)
{
int* p_i = (int*)Data;
int &refcount = *(p_i-2);
if (--refcount == 0)
FreeData();
}
}
template <class T>; T*
DynamicArray<T>;::AllocData(int count)
{
if (count == 0)
return 0;
int *pi = (int*)malloc(sizeof(T)*count + 2*sizeof(int));
*pi++ = 1; // RefCount initialized to 1
*pi++ = count; // Set length of array
T *pt = (T*)pi;
char *pc = (char*)pi;
T *p = (T*)pc;
while (count-- >; 0)
{
new (pc) T;
pc = (char*)(++p);
}
return pt;
}
template <class T>; void
DynamicArray<T>;::SetData(T* t)
{
if (Data != t)
{
DecRefCount();
Data = t;
}
}
template <class T>; void
DynamicArray<T>;::FreeData()
{
if (Data)
{
T* p = Data;
int l = (*this).get_length();
for (; l-- >; 0; p++)
p->;~T();
int* p_i = (int*)Data;
p_i -= 2;
free(p_i);
Data = 0;
}
}
#endif |
aix下的c++(template)問題(向高手請教。。有難度)
看來這裡還是用c得人多一點啊!!! |
aix下的c++(template)問題(向高手請教。。有難度)
使用c++的也有很多
但是代碼那麼亂
是給別人看的嗎
大家都有自己的事要做
不可能很有時間在這回答問題的
自己使用論壇發貼功能的code對齊一下
置頂的發貼規則中有 |
aix下的c++(template)問題(向高手請教。。有難度)
-->
同意!!! :lol: |
| |