c++

Virtual function

class a { virtual void foo(void) ; }; class b : public a { public: virtual void foo(void) { cout<< "class b"; } }; int main ( ) { class a *b_ptr = new b ; b_ptr->foo(); } please guide me why the b_ptr->foo() will not call the foo() function of the class b? ...

java Map keyset equivalent for C++ STL Map

I tried searching documentation but couldn't find an equivalent of keyset function for maps in C++ stl. Is it C++ really that poor. ...

How to debug a running C++ program in Linux?

Hi I have a question about debugging a running C++ program in Linux. If a programming is already running and can't be interrupted, how to do that. I can find three ways, but I don't know too much about details, I am grateful if any one can elaborate it deeper. 1) we can use GDB by specifying the process ID gdb -p PID In this case...

What is a good CPU/PC setup to speed up intensive C++/templates compilation?

I currently have a machine with an Opteron 275 (2.2Ghz), which is a dual core CPU, and 4GB of RAM, along with a very fast hard drive. I find that when compiling even somewhat simple projects that use C++ templates (think boost, etc.), my compile times can take quite a while (minutes for small things, much longer for bigger projects). Unf...

Memory efficient way to remove duplicate lines in a text file using C++

What is the most memory efficient way to remove duplicate lines in a large text file using C++? Let me clarify, I'm not asking for code, just the best method. The duplicate lines are not guaranteed to be adjacent. I realize that an approach optimized for minimal memory usage would result in slower speeds however this is my restriction...

What type can hold member-function-pointers of difference classes in C++?

Hi all, I need an array to hold member-function-pointers of different classes. How can I define the array? The code should look like this : arr[0] = &CMyClass::FuncX; arr[1] = &CYourClass::FuncY; arr[2] = &CHerClass::FuncZ; I tried void*, but it doesn't work. Thanks. Best regards, Zach@Shine ...

Sort CMap Key by String Length

Previously, I am using STL map to perform the mentioned task. struct ltstr { bool operator()(std::string s1, std::string s2) const { const int l1 = s1.length(); const int l2 = s2.length(); if (l1 == l2) { // In alphabetical order. return s1.compare(s2) < 0; } // From longest leng...

The fastest way to iterate through a collection of objects

Hello all, First to give you some background: I have some research code which performs a Monte Carlo simulation, essential what happens is I iterate through a collection of objects, compute a number of vectors from their surface then for each vector I iterate through the collection of objects again to see if the vector hits another obje...

How can I change the precision of printing with the stl?

This might be a repeat, but my google-fu failed to find it. I want to print numbers to a file using the stl with the number of decimal places, rather than overall precision. So, if I do this: int precision = 16; std::vector<double> thePoint(3); thePoint[0] = 86.3671436; thePoint[0] = -334.8866574; thePoint[0] = 24.2814; ofstream file...

TeeChart VCL vs .NET

Is TeeChart .NET built from the same source as TeeChart VCL? I'm just wandering as we have a VCL application heavily dependent on TeeChart and I would like to redevelop the GUI component in .NET so I can switch from the Codegear IDE to Visual Studio. ...

How can I eliminate an element in a vector if a condition is met

Hi, I have a vector of Rect: vector<Rect> myRecVec; I would like to remove the ones which are overlapping in the vector: So I have 2 nested loop like this: vector<Rect>::iterator iter1 = myRecVec.begin(); vector<Rect>::iterator iter2 = myRecVec.begin(); while( iter1 != myRecVec.end() ) { Rectangle r1 = *iter1; while( iter2 ...

Is there any c++ class that can't be used in STL?

Just come up with this question. Any hint? ...

C/C++ for Core Logic Development of a Web Application?

Can C/C++ be choice of keeping all your logic (business/domain) for web application? Why? I've two resources (cousins) having knowledge on C/C++ and me also good in C/C++, Python, HTML, CSS and JavaScript. We like to utilize our free time to work on our some good ideas we developed together. The ideas require knowledge of web applica...

PhysX Question about Raycasting - Setting the shape masks

I am trying to make the raycast give me the distance of the terrain and nothing else. But I'm not sure how to use the group Mask Filter. virtual NxShape* raycastClosestShape ( const NxRay& worldRay, NxShapesType shapeType, NxRaycastHit& hit, NxU32 groups=0xffffffff, NxReal maxDist=NX_MAX_F32, NxU32 hintFlags=0xffffffff...

pthreads and C++

I am playing with C++ and pthreads and so far so good. I can access a class member function if it's static and I've read that I can access a normal class member functions if I pass "this" as an argument with pthread_create, because c++ does this to, under the hood. But my problem is that I want to give an int to that function, and I don'...

Why can't a std::vector take a local type?

void foo() { struct Foo { .. }; std::vector<Foo> vec; // why is this illegal? } I'm not returning Foo to the outside world. It's just a temporary type that I use within the function. ...

Size of a class with 'this' pointer

The size of a class with no data members is returned as 1 byte, even though there is an implicit 'this' pointer declared. Shouldn't the size returned be 4 bytes(on a 32 bit machine)? I came across articles which indicated that 'this' pointer is not counted for calculating the size of the object. But I am unable to understand the reason f...

How to reliably replace a library-defined error handler with my own?

On certain error cases ATL invokes AtlThrow() which is implemented as ATL::AtlThrowImpl() which in turn throws CAtlException. The latter is not very good - CAtlException is not even derived from std::exception and also we use our own exceptions hierarchy and now we will have to catch CAtlException separately here and there which is lots ...

Cannot understand how new or malloc does work with BYTE*

I trying to allocate memory for 10 bytes BYTE* tmp; tmp = new BYTE[10]; //or tmp = (BYTE*)malloc(10*sizeof(BYTE)); But after new or malloc operation length of *tmp more than 10 (i.e. '\0' char not in 10 position in tmp array) Why? ...

How can I make `new[]` default-initialize the array of primitive types?

Every now and then I need to call new[] for built-in types (usually char). The result is an array with uninitialized values and I have to use memset() or std::fill() to initialize the elements. How do I make new[] default-initialize the elements? ...