由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 一个C++ operator new的重载问题
相关主题
make 时候遇到 undefined reference 怎么办?stl Compare为何需要重载()?
C++ delete求教new delete 在c++中的重载
大侠们救命, C++ operator new 问题vc2008下编译的问题
为什么不能成功排序一个指向指针的指针的引用?
STL怎样同时重载()和< ?fatal error C1001: INTERNAL COMPILER ERROR
C++命名空间和算子重载程序从VC6挪到VC2008后,执行速度低了15-30%
关于placement newdebug的问题
C++ Q02:没有经过构造函数???
相关话题的讨论汇总
话题: string话题: vector话题: include话题: operator话题: sz
进入Programming版参与讨论
1 (共1页)
d**********o
发帖数: 41
1
我想把一个class A的new 重载成:
void* operator new(size_t sz, string s){...}
在这个class A里有一个静态的vector,记录string s
也就是说这个vector在每次动态分配空间的时候记录一些信息,比如__FILE__, __LINE
__
但是编译出错说C1001 an internal error has occurred in the compiler, 看了半天不
知道怎么错了
OS: windows XP
DE: VC2008
code 见下
d**********o
发帖数: 41
2
#include
#include
#include
#include
#include
using namespace std;
class A{
static vector log; //log for dynamic mem alloc, static
string name;
public:
A(string s):name(s){}
void* operator new(size_t sz, string s){
log.push_back(s);
void* p=0;
if(!(p=malloc(sz))) throw bad_alloc();
return p;
}
void showLog(unsigned int index){
cout< }
};
vector
d**********o
发帖数: 41
3
如果我把静态的vector成员变成vector,就都正确了
是不是编译开始的时候分配静态成员内存的时候vector的大小不能确定?
下面的程序是正常的
//=============================================
#include
#include
#include
#include
#include
using namespace std;
class A{
static vector log; //log for dynamic mem alloc, static
string name;
public:
A(string s):name(s){}
void* operator new(size_t sz, int s){
log.push_back(s);
void* p=0;
if(!(p=malloc(sz))
t****t
发帖数: 6806
4
try not to use "string s" in prototype
use const string& s
i.e.
void* operator new(size_t sz, const string& s)
but anyway, internal errors are always compiler bug

LINE
天不

【在 d**********o 的大作中提到】
: 我想把一个class A的new 重载成:
: void* operator new(size_t sz, string s){...}
: 在这个class A里有一个静态的vector,记录string s
: 也就是说这个vector在每次动态分配空间的时候记录一些信息,比如__FILE__, __LINE
: __
: 但是编译出错说C1001 an internal error has occurred in the compiler, 看了半天不
: 知道怎么错了
: OS: windows XP
: DE: VC2008
: code 见下

d**********o
发帖数: 41
5
嗯,谢谢楼上大侠
1 (共1页)
进入Programming版参与讨论
相关主题
没有经过构造函数???STL怎样同时重载()和< ?
请各位推荐学习visual c++的书C++命名空间和算子重载
third party c/c++ code and compile it on win 7关于placement new
重载 ^ 操作符编译出错C++ Q02:
make 时候遇到 undefined reference 怎么办?stl Compare为何需要重载()?
C++ delete求教new delete 在c++中的重载
大侠们救命, C++ operator new 问题vc2008下编译的问题
为什么不能成功排序一个指向指针的指针的引用?
相关话题的讨论汇总
话题: string话题: vector话题: include话题: operator话题: sz