c++

Clarification on lists and removing elements

If I have a list<object*>>* queue and want to pop the first object in the list and hand it over to another part of the program, is it correct to use (sketchy code): object* objPtr = queue->first(); queue->pop_first(); return objPtr; // is this a pointer to a valid memory address now? ? According to the documentation on http://www.cp...

What is going on with Steve Dewhurst, is he up-to-date in terms of C++?

For those who don't know, he is an author of C++ Gotchas and C++ Common Knowledge, and allegedly an acclaimed expert in C++. However, his website is fairly outdated, he hasn't published articles nor books for a very many years now, and, I am afraid to say completely, disappeared from C++ community. What do you guys think of his books, ...

Preprocessor definitions going haywire. int define redefinition?

I am trying to add a preprocessor definition so that a value is only defined while a certain project is building, then it becomes undefined. I have gone into my project properties -> preprocessor -> preprocessor definitions. In here, I typed #define PROJECTNAME_EXPORT, in hopes that I could call #ifdef PROJECTNAME_EXPORT throughout tha...

How to [portably] get DBL_EPSILON in C/C++

I am using gcc 3.4 on linux (AS 3) and trying to figure out to get DBL_EPSILON number, or at least a decent approximation. How to get it programmatically? How can I do that? ...

How to get the name of an Event from a handle

I have an array of Win32 event handles that I'm waiting on using WaitForMultipleObjects(). This returns the index in the array of events that triggered but what I need to know is the name of the event. I've been looking through MSDN and can't see anything to do this. Basically I have a class that monitors the registry through events u...

Close LogonUser Handle if Failed Logon?

The LogonUser function http://msdn.microsoft.com/en-us/library/aa378184(VS.85).aspx returns a handle that you can use to impersonate the user, when you are done using it you call CloseHandle to close it. My question is, do you need to close the handle if the logon attempt fails (ie wrong username or password)? ...

Accessing a method from a templated derived class without using virtual functions in c++?

How do I get around this? I clearly cannot make the value() method virtual as I won't know what type it is beforehand, and may not know this when accessing the method from b: class Base { public: Base() { } virtual ~Base() { } private: int m_anotherVariable; }; template <typename T> class Derived : public Base { public: ...

What is being done in this bit shifting operation?

(INBuffer[3] << 8) + INBuffer[2] Is this essentially moving the bit in INBuffer[3] into INBuffer[2] or [3] being zero'ed out then added to [2]? ...

Is a cgi different from a console application?

I am having some problems in running cgi on my Apache (Windows, XAMPP), but the exe runs smoothly on the command prompt. Reading the logs on Apache folder it gives no information about the error. Any ideas about this? ...

FILETIME to __int64

What is the proper way to convert a FILETIME structure into __int64? Can you please tell me? ...

WNetAddConnection2 in Windows 7 with Impersonation and no Error Code

I'm doing some crazy impersonation stuff to get around UAC dialogs in Windows 7 so the user does not have to interact with the UI (I have the admin creds of course). I have a process running as the Administrator and elevated past UAC. The issue that I'm facing is that when I make a call to WNetAddConnection2, within this process, I am ...

Difference between variable-length argument and function overloading

This C++ question seems to be pretty basic and general but still I want someone to answer. 1) What is the difference between a function with variable-length argument and an overloaded function? 2) Will we have problems if we have a function with variable-length argument and another same name function with similar arguments? ...

LNK2019 when converting an app to use DLLs

(Re-written for clarity) I have a multi-project solution that I am looking to convert from using .lib to .DLL files. I have created my declspec macros and applied it to **every class except for those in the project that creates the final .exe. The linker is throwing a fit on just about everything, however. I have set up to ignore err...

Singleton in a DLL?

So i am trying to export somethings in a project to DLL. Anyways a few of the projects use a singleton class very heavily. template <typename T> class DLL_IMP VA_Singleton { protected: VA_Singleton () {}; ~VA_Singleton () {}; public: static T *Get(){ return (static_cast<T*> (a_singleton)); } static void Dele...

How do I iterate over cin line by line in C++?

I want to iterate over cin, line by line, addressing each line as a std::string. Which is better: string line; while (getline(cin, line)) { // process line } or for (string line; getline(cin, line); ) { // process line } ? What is the normal way to do this? ...

"const T &arg" vs. "T arg"

If you have a function which takes for example an int, what is the better way of declaring the function and why is one better than the other one? void myFunction (const int &myArgument); or void myFunction (int myArgument); ...

How do I set a specific printer for a report?

I want to print a customized report to a specific printer, bypassing the print dialog. The printer is to be selected by the user for each report template. Right now I have the code to print the report showing the print dialog, or directly to the default printer. I need to change it in order to print directly to a printer which is not n...

use of extern methods between dll projects?

I have a debug condition to manage memory where I have extern void* operator new(unsigned int size, const char* file, int line); extern void operator delete(void* address, const char* file, int line); extern void Delete(void* address); #define FUN_NEW new(__FILE__, __LINE__) #define FUN_DELETE delete This exists in...

Simple 'for' loop crashing program on final iteration

The below program seems to be crashing at the very end each time, and I'm assuming that this is because once I get to i = (size-1) then wordList[i+1] won't return anything, returns null, or something equivalent. Any way around this? Am I correct that this is the source of my problem? #include <iostream> #include <string> #include <vecto...

Boost C++ date_time microsec_clock and second_clock

I discovered a strange result in Boost C++ date time library. There is inconsistency between microsec_clock and second_clock, and I don't understand why is that. I am using Windows XP 32-bits My snip of code: using namespace boost::posix_time; ... ptime now = second_clock::universal_time(); std::cout << "Current Time is: "<< to_iso_ext...