c++

How to deprecate a macro in GCC?

Hi, i Know how to use attribute deprecated to deprcate a function like this: int old_fn () __attribute__ ((deprecated)); But how to deprecate a Macro like this: #define OLD_MACRO 1 Thank you in advance. Eric ...

dynamical binding or switch/case?

A scene like this: I've different of objects do the similar operation as respective func() implements. There're 2 kinds of solution for func_manager() to call func() according to different objects Solution 1: Use virtual function character specified in c++. func_manager works differently accroding to different object point pass in. ...

How to detect missing font characters

Is there a way to detect that all characters are displayed properly with the current font? In some environments and fonts certain characters are replaced with a square symbol. I'd like to automatically verify that all characters used in the GUI are supported by the current font. ...

Howto access thread data outside a thread

Question: I start the MS Text-to-speech engine in a thread, in order to avoid a crash on DLL_attach. It starts fine, and the text to speech engine gets initialized, but I can't access ISpVoice outside the thread. How can I access ISpVoice outside the thread ? It's a global variable after all... You find XPThreads here: http://www.codepr...

Invalidate() debug assertion failed message (MFC, VC++)

I've made a custom control, and when I want it to repaint on the screen I call Invalidate(), and afterwards UpdateWindow(), but i get message: debug assertion failed for a file afxwin2.inl in line 150 which is: AFXWIN_INLINE void CWnd::Invalidate(BOOL bErase) { ASSERT(::IsWindow(m_hWnd)); ::InvalidateRect(m_hWnd, NULL, bErase); } ...

How can I determine which dependency would cause a C++ compilation unit to be rebuilt?

I have a legacy C++ application with a deep graph of #includes. Changes to any header file often cause recompiles of seemingly unrelated source files. The application is built using a Visual Studio 2005 solution (sln) file. Can MSBUILD be invoked in a way that it reports which dependency(ies) are causing a source file to be recompiled...

C++ custom exceptions: run time performance and passing exceptions from C++ to C (as error info)

I am writing a custom C++ exception class (so I can pass exceptions occuring in C++ to another language via a C API). My initial plan of attack was to proceed as follows: //C++ myClass { public: myClass(); ~myClass(); void foo() // throws myException int foo(const int i, const bool b) // throws myException } * myClassPtr;...

What code commenting style should I use for both C++ and C# ?

Hi, I was recently hired in a company. They have a lot of C++ and C# code source files and almost one different commenting style per file. (Well this is exagerated, but you have the picture) This morning, I show my new collegues how my personnal code was commented and how easy it was to generate a documentation from it (I use Doxygen)...

What iterator to return for non-existing map How to signkey?

I want to have a function which searches for a key in a collection of maps and returns an iterator to the found key. But what should be returned in case the key cannot be found? I cannot return map::end since the collection of maps can be empty. Thanks. map<string, string>::iterator CConfFile::GetKey(const string &SectionName, const st...

writing string into file before calling the close()

I am using ofstream() to write data into file, i want the program to perform such a way that it should be keep on writting the string into the file as soon as the value gets assingned to string variable, and it should be writting before calling the close(). The need is, I am getting the keystrokes of the keyboard, and i want it to be st...

c++ Array passing dilemma

Hi, I am writing a function that takes a string, string pointer and an int. The function splits the string based on a set of rules and puts each token into an array. I need to return the array out of the function with the number of elements in the int variable etc. I am stuck as to how I return the array as I can not use auto other wise...

Problem with "moveable-only types" in VC++ 2010

I recently installed Visual Studio 2010 Professional RC to try it out and test the few C++0x features that are implemented in VC++ 2010. I instantiated a std::vector of std::unique_ptr, without any problems. However, when I try to populate it by passing temporaries to push_back, the compiler complains that the copy constructor of unique...

C++ : Initializing base class constant static variable with different value in derived class ?

I have a base class A with a constant static variable a. I need that instances of class B have a different value for the static variable a. How could this be achieved, preferably with static initialization ? class A { public: static const int a; }; const int A::a = 1; class B : public A { // ??? // How to set *a* to a valu...

Incremental Union?

I'm trying to describe a Sudoku Board in C++ with a union statement: union Board { int board[9][9]; int sec1[3][3]; int sec2[3][3]; int sec3[3][3]; int sec4[3][3]; int sec5[3][3]; int sec6[3][3]; int sec7[3][3]; int sec8[3][3]; int sec9[3][3]; } Would each section of the board correspond wi...

Smart pointers and polymorphism

hello. I implemented reference counting pointers (called SP in the example) and im having problems with polymorphism which i think i shouldn't have. In the following code: SP<BaseClass> foo() { // Some logic... SP<DerivedClass> retPtr = new DerivedClass(); return retPtr; } DerivedClass inherits f...

RegQueryValueEx function fails On Windows7

Hi All, I have a dll made in cpp which tries to read/write some Registry Keys. This code runs perfectly fine in Windows XP (32 bit environment) but it fails in Windows 7(64 bit environment). The registry keys which this application accesses is the shared registry keys. These keys are not part of 32 bit registry cache(wow32 bit) or 64...

Exiting from the Middle of an Expression Without Using Exceptions

Solved: I figured out a clean way to do it with setjmp()/longjmp(), requiring only a minimal wrapper like: int jump(jmp_buf j, int i) { longjmp(j, i); return 0; } This allows jump() to be used in conditional expressions. So now the code: if (A == 0) return; output << "Nonzero.\n"; Is correctly translated to: return ((A == 0) && ju...

int24 - 24 bit integral datatype

Hi, is there a 24Bit primitive integral datatype in C++? If there is none, would it be possible to create a class int24 (, uint24 ) ? it's purpose could be: * manipulating soundfiles in 24 bit format * manipulating bitmapdata without alphachannel many thanks in advance Oops ...

OpenSSL Bio chains: Clarrification on documentation

The documentation for Openssl memory BIO sinks is here. I am creating a BIO chain to turn binary strings into base64 strings. The source/sink is always a memory location, and this enables me to just keep the same chain arround. However the data (should) go into a memory buffer managed by OpenSSL when I write to it, and it should come fr...

Cannot Convert from int[][] to int*

I have a 3x3 array that I'm trying to create a pointer to and I keep getting this array, what gives? How do I have to define the pointer? I've tried every combination of [] and *. Is it possible to do this? int tempSec[3][3]; int* pTemp = tempSec; ...