我的问题(在此之后,对于长篇介绍感到抱歉,问题在于粗体)最初的灵感来自于Herb Sutters Exceptional C++中的第23项,我们发现这样的内容:
<snip>
...
int main()
{
GenericTableAlgorithm a( "Customer", MyWorker() );
a.Process();
}
同
class GenericTableAlgorithm
{
public:
GenericTableAlgorithm( const string& table,
GTAClient& worker );
bool Process();
private:
struct GenericTableAlgorithmImpl* pimpl_; //implementation
};
class GTAClient
{
///...
virtual bool ProcessRow( const PrimaryKey& ) =0;
//...
};
class MyWorker : public GTAClient
{
// ... override Filter() and ProcessRow() to
// implement a specific operation ...
};
</剪断>
现在,我对该代码存在以下问题(不,我绝不怀疑Sutter先生作为C++专家的实力):
MyWorker …问题类似于这个bug
关于在C++中将数组存储在std :: vector中的问题
但出于不同的原因(见下文).
对于C++中的以下示例程序:
#include <vector>
int main(int c_, char ** v_)
{
const int LENGTH = 100;
std::vector<char[LENGTH]> ca_vector;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC 4.2.3编译干净.GCC 4.3.2发出以下错误:
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = char [100]]’: /usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h:103: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = char (*)[100]]’ /usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h:128: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator&) [with _ForwardIterator = char (*)[100], _Tp = char [100]]’ /usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_vector.h:300: instantiated from ‘std::vector::~vector() [with _Tp = char [100], _Alloc = std::allocator]’ test.cpp:7: instantiated from …