c++

C++: Call destructor and then constructor (resetting an object)

Hi. I want to reset an object. Can I do it in following way? anObject->~AnObject(); anObject = new(anObject) AnObject(); // edit: this is not allowed: anObject->AnObject(); This code is obviously a subset of typical life cycle of an object allocated by in placement new: AnObject* anObject = malloc(sizeof(AnObject)); anObject = new (a...

Visual Studio 2008 build errors ...

Hi, I'm trying to compile an old project that was originally designed for Visual Studio 2008 SP0 (I'm using SP1 now). I'm getting these errors. Error 51 error LNK2019: unresolved external symbol "unsigned long __cdecl GetDeviceState(enum DEVICES_ENUM,enum DEVICE_STATE_ENUM &,int &)" (?GetDeviceState@@YAKW4DEVICES_ENUM@@AAW4DEVICE_STAT...

Memory allocators

I want to make a virtual allocator using c++ on windows,, which allocate data on a file on the hard disk, to reduce physical memory usage when allocate large objects !.. I don't want to use system virtual memory with virtualAlloc.. . I want to create a file on the disk and use it to allocate the whole objects and then move the part or th...

How do I set the executable attributes with qmake for a c++ project?

I use buildbot to compile my Qt/C++/nmake project. I would like to add the version number to the executable and the company details (on the properties of the file). Does anybody know where I can set this information? Note: I am using buildbot not Visual Studio so I need a command line way of doing this. ...

How to do an active sleep?

I am running some profiling tests, and usleep is an useful function. But while my program is sleeping, this time does not appear in the profile. eg. if I have a function as : void f1() { for (i = 0; i < 1000; i++) usleep(1000); } With profile tools as gprof, f1 does not seems to consume any time. What I am looking is a ...

gui for mpi program

Hi, I have a problem about a simple mpi program.This program have some 3D points and these points are moving during the program. I created an simple code by implemented c++ and then I tried to add an simple gui. I used gnuplot library and I have a problem. When I call the gui function the gui is created and it is disappeared at the same ...

Accessing members of an array of structures in C++

Working through C++ Primer Plus and am trying to cin data to a dynamically allocated array of structures. One of the items is a char array. How do I write to these struct members? Posting code of my wrong attempt so you can see what I'm trying to do. #include <iostream> using namespace std; struct contributions { char name[20];...

POD class initialized with placement new default initialized?

If I initialize a POD class with placement new, can I assume that the memory will be default initialized (to zeros)? This resource clearly states that if you call the zero argument default constructor explicitly that the fields will be default initialized, but it is not clear if this would hold true using the default implementation of pl...

where can I find a good boost reference?

I'd like to have a good up-to-date reference for boost by my side, and the only books I found are the following: Beyond the C++ Standard Library: An Introduction to Boost The C++ Standard Library Extensions: A Tutorial and Reference Both books are somewhat dated, and I am sure boost has been evolving. Obviously I can just use a d...

Why does strlen() return a 64-bit integer? Am i missing something?

When compiling a 64bit application, why does strlen() return a 64-bit integer? Am i missing somthing? I understand that strlen() returns a size_t type, and by definition this shouldn’t change, but... Why would strlen need to return a 64-bit integer? The function is designed to be used with strings. With that said: Do programmers commo...

Preprocessor switch determining version of a class

I have a class with two possible implementations, depending on a preprocessor switch. The way I have handled this is to create "src\CompSwitch1\class.h" and "src\CompSwitch2\class.h". In my standard include file, I use #ifdef CompSwitch1 #include "CompSwitch1\class.h" #elif CompSwitch2 #include "CompSwitch2\clas...

How to find the width of a String (in pixels) in WIN32

Can you measure the width of a string more exactly in WIN32 than using the GetTextMetrics function and using tmAveCharWidth*strSize? ...

Class issue, adding a day

I'm trying to make the add_day function work, but I'm having some trouble. Note that I can't make any changes to the struct(it's very simplistic) because the point of the exercise is to make the program work with what's given. The code is #include "std_lib_facilities.h" struct Date{ int y, m, d; Date(int y, int m, int d);...

Edit the frame rate of an avi file

Is it possible to change the frame rate of an avi file using the Video for windows library? I tried the following steps but did not succeed. 1) AviFileInit 2) AviFileOpen(OF_READWRITE) 3) pavi1 = AviFileGetStream 4) avi_info = AviStreamInfo 5) avi_info.dwrate = 15 6) EditStreamSetInfo(dwrate) returns -2147467262. ...

Problem with WH_SHELL

I'm trying to create a Windows hook, specifically to catch HSHELL_WINDOWCREATED messages. However, my hook proc never gets called. My dll has a function to install the hook: hHook = SetWindowsHookEx(WH_SHELL, (HOOKPROC)CreateWindowHook, hinst, 0); hinst was filled in by DllMain(), at the DLL_PROCESS_ATTACH message. CreateWindowHook i...

Class in a Structure in C++

Can we define a Class within a Structure? If yes then how? And what will be the syntax of that? ...

Advise HTMLElementEvents2 sink (MSDN website)

From the msdn website void CMyClass::ConnectEvents(IHTMLElement* pElem) { HRESULT hr; IConnectionPointContainer* pCPC = NULL; IConnectionPoint* pCP = NULL; DWORD dwCookie; // Check that this is a connectable object. hr = pElem->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC); if (SUCCEEDED(hr))...

source code of c/c++ functions

Hello, I wanted to have a look at the implementation of different C/C++ functions (like strcpy, stcmp, strstr). This will help me in knowing good coding practices in c/c++. Could you let me know where can I find it? Thanks. ...

difference of variable in placement of private keyword in a MFC class

Using the following code snippet as an illustration to my question: // #includes and other macros class MyClass : public CFormView { private: DECLARE_DYNCREATE(MyClass) bool privateContent; ... public: bool publicContent; ... }; class MusicPlayer { public: AppClass *theApp; // which has a pointer...

Structure Constructor in C++?

Can a struct have a constructor in C++? I have been trying to solve this problem but not getting any syntax. ...