c++

Rounding to the second decimal spot

how do i round to the second decimal point in C++. thanks for your help. ...

Linker problem in Release when trying to add GLUI library to project

Hi! I try to add the GLUI library to my project. Compiling in Debug mode runs fine. But if I compile in Release, it gives me a bunch of LNK2005 errors saying things like: error LNK2005: _realloc already defined in Libcmt.lib(realloc.obj) ok - i already got some similar Linker problems before because I use both CRT and MFC in my app b...

What's the use of the derived class as a template parameter?

What's the purpose of this pattern? What is it called? It looked very strange when I saw it the first time, though I have now seen it many times. template<typename Derived> struct Base { //... }; struct Example : Base<Example> { //... }; ...

Problem with STL map iterator copying

I have an STL map that I want to iterate through, and can't seem to get the code to work. The code is: //PowerupInfo is a struct defined in this class's header file std::map<std::string, PowerupInfo> powerups; ...populate powerups std::map<std::string, PowerupInfo>::iterator iter; for (iter = powerups.begin(); iter != powerups.end(); ...

NULL pointer conversion

C++03 $4.10- "The conversion of a null pointer constant to a pointer to cv-qualified type is a single conversion, and not the sequence of a pointer conversion followed by a qualification conversion (4.4)." Here is my understanding int main(){ char buf[] = "Hello"; char const *p1 = buf; // 2 step conversion proces...

painting by mouse click in qt

Hello, I have a class Square based in QWidget, it's game board consisting of rectangles 8x8. I draw this rectangles in my widget in: void Square::paintEvent(QPaintEvent *) Now i must click on some rectangle and in this rectangle must draw ellipse. I try: void Square::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftB...

c++ What to do if Library makes use of debug version of other library?

Hi! A library i'd like to use makes calls to functions like "malloc_dbg" which are defined in libcmtd.lib but not in libcmt.lib (so I get Linker errors in Release mode) Do I really need to use the debugversion of that lib even in releasemode? or can I somehow use libcmt.lib and libcmtd.lib together, but use libcmtd.lib only for this ot...

How to validate a valid integer and floating number in VC++ CString

Can some one tell me a valid way to validate a number present in CString object as either a valid integer or floating number? ...

Convert a QDateTime in UTC to local system time

I construct a QDateTime from a string like this: QDateTime date = QDateTime::fromString("2010-10-25T10:28:58.570Z", "yyyy-MM-ddTHH:mm:ss.zzzZ"); I know that date is in UTC because that is the way it's stored. But when I want to display this date to the user, it should be in the user's local time zone. date.toLocalTime() looks promisin...

ADT - Iterators - operator ++

This isnt a homework question. I took data structures at a Community College and now that i am at the university i talked to the teacher about there data structures class. Now, since its really different and the class i took transferred, He gave me one of there assignments and said play with it. We never did any containers, wrappers,temp...

keep the track of placement delete against placement new

Hi, I am developing a tool like memory leak detector. I can track the placement new but how can i track the placement delete. I did a lot of R & D and i found that placement delete cant be called directly, it is called by constructor at the time of exception. So how can i keep the track of placement delete against placement new? Any he...

sort numbers by digit

why this code does not work? it does not show me output #include <stdlib.h> #include <iostream> #include <string.h> void Sort(int *arr,int length){ int *iter=arr; char buf[12],buf1[12]; while ((iter++)< (arr+length)){ if (iter==arr || (strcmp(itoa(*iter,buf,10),itoa(*(iter-1),buf1,10))>=0)){ iter++; ...

Using SecureZeroMemory in Delphi

I understand there is a SecureZeroMemory function in C. The function implementation is defined in <WinnNT.h> as RtlSecureZeroMemory function. QNS: How can SecureZeroMemory be used in Delphi? Did Delphi release a library that contains that function? I'm using Delphi 7. Windows.pas only has ZeroMemory but not SecureZeroMemory. ...

Library function returns raw pointer and I want to use smart pointer

I have this situation where the library I use has many functions that return raw pointers to objects, how could I now use boost smart pointers in my program using this library and using smart pointers? The library is xerces-C++ and an example is getting the document iterator: boost::shared_ptr<DOMNodeIterator> itera = document->createN...

Will a "variableName;" C++ statement be a no-op at all times?

In C++ sometimes a variable will be defined, but not used. Here's an example - a function for use with COM_INTERFACE_ENTRY_FUNC_BLIND ATL macro: HRESULT WINAPI blindQuery( void* /*currentObject*/, REFIID iid, void** ppv, DWORD_PTR /*param*/ ) { DEBUG_LOG( __FUNCTION__ ); //DEBUG_LOG macro expands to an empty string in non-debug ...

Does placement new call the constructor if the passed pointer is null?

Hello guys, I tried to converted a vc7.1 project to vs2010 which I got from codeproject.(And here's the link h tt p://www.codeproject.com/KB/cpp/transactions.aspx?fid=11253&df=90&mpp=50&noise=3&sort=Position&view=Expanded&fr=1#xx0xx But after converted and modified its configuration. I find it debug unsuccessfully, it says Unhandled ex...

kill boost thread after n seconds

I am looking for the best way to solve the following (c++) problem. I have a function given by some framework, which returns an object. Sometimes it takes just miliseconds, but on some occasions it takes minutes. So i want to stop the execution if it takes longer than let's say 2 seconds. I was thinking about doing it with boost threads...

Why is "operator void" not invoked with cast syntax?

While playing with this answer by user GMan I crafted the following snippet (compiled with Visual C++ 9): class Class { public: operator void() {} }; Class object; static_cast<void>( object ); (void)object; object.operator void(); after stepping over with the debugger I found out that casting to void doesn't invoke Class:...

Dll Memory Management

I have few doubts regarding how windows manages a .dll's memory. when .dll's are loaded into the host process, how is the memory managed? Does .dll get access to the entire memory available to the host process or just a portion of it? i.e is there a limitation when memory is allocated by a function inside the .dll? Will STL classes li...

Efficient way to remove items from vector

Currently, I plan to remove all items from vector, which is not found in a set. For example : #include <vector> #include <set> #include <string> #include <iostream> using namespace std; int main() { std::set<string> erase_if_not_found; erase_if_not_found.insert("a"); erase_if_not_found.insert("b"); erase_if_not_found....