May 2, 1997

Memory re-allocation

Question: Is there a standard method/operator in C++ analogous to standard C’s realloc() function that enables resizing of dynamic memory allocated by new operator? Answer: There is no standard call defined in C++ to reallocate memory once it has beencreated using new. The easiest way of doing it is to

I get a runtime error when I use the array delete operator

Question: This is legal (safe) and works with the compilerenvironment I am using: CMyObject *ptr = NULL; delete ptr;However, I get a run-time error (assert) whenI use the array delete operator: long *array = NULL; delete [] array;Is the environment right or is it legal C++ to use array delete

C++ Program Performance Monitor

Question: Do you know of a good tool for getting performance data on a pure C++ program?I need a tool that indicates sections of code thatuse the most CPU/memory, etc. Answer: Many development environments include a profiling tool that helpsanalyze which functions are called most and how much memory a

Inherited operator = not being seen

Question: I have a templated class A that defines two operator =, and a templated class B : public class A which should inherit the two virtual a::operator = I define, but when I instantiate an object B b, it won’t see the operator = . Answer: You are not

Constructor with static members in library

Question: Background: Digital UNIX 3.2g, Alpha platform, latest GNU.From the FAQ, I know that you are supposed to declare static member variables externally from the declaration and inonly one place. But our group has run into a problem with that. The code below works fine when it’s just a couple

Defining behavior in one constructor, then letting two others call it

Question: I defined a class A, which has three constructors:A(), A(int), A(int, int)Can I just define the behavior in one constructor, say A(int, int), and let the other two constructors call A(int, int)? I can do that in Java.For example,public class A{ public A() { this(1, 2); } pub A(int

Using macros to simulate “delphi” properties in C

Question: Is there a way to do some macro magic with members of a given class sothat when a designated name is called, itinvokes the macro that called the class member,such as:class Point{ int x,y;public: void Set_X(int n){x=n;} int Get_X(){return x;} … etc …};#define PROPERTY(name,read,write)………..//use macro on point classPROPERTY(X,Get_X,Set_X);…. Point

How to move from beginner to intermediate C/C++

Question: I am a C/C++ programmer who is moving from the beginner to intermediate level. My question is, how does one move successfully from the beginner to intermediate level? Answer: Hmm … interesting question.I think I’ll just explain how I went about learning C++ and applying what I learned to