c++

Function try blocks, but not in constructors

Hello, just a quick question. Is there any difference between void f(Foo x) try { ... } catch(exception& e) { ... } and void f(Foo x) { try { ... } catch (exception& e) { ... } } ? If no, why are function try blocks for (the case of initialization lists for constructors being put aside) ? What happens...

What is the correct way to initialize HRESULT?

I'm using C++ in Visual Studio 2005 and I'm getting many warnings that read potentially uninitialized local variable 'hr' used Where hr is defined as HRESULT hr; What's the correct way to initialize HRESULT? ...

How to handle pressure to deliver, when maintaining legacy code?

Here's a question that has been bugging me. I'd like to think that I prefer writing elegant C++ code. — You know, well designed, clean, documented code. But, what do you do if you are under pressure to deliver and maintain large legacy code which is supposed to meet functional and, especially, performance requirements? After a while, my...

Why is std::type_info polymorphic?

Is there a reason why std::type_info is specified to be polymorphic? The destructor is specified to be virtual (and there's a comment to the effect of "so that it's polymorphic" in The Design and Evolution of C++). I can't really see a compelling reason why. I don't have any specific use case, I was just wondering if there ever was a rat...

White-box testing - friends or preprocessor?

So, imagine we have a class like this class Testee { public: void Func() private: void auxFunc() }; and we want to do white-box unit-testing on it. Which do you think is a better approach? To declare the tester class a friend of the testee class? Or use the preprocessor like this: class Testee { public: void Fu...

How can etags handle multiple directories

How it is possible under emacs and C++ to extend etags covering multiple directories? (I am not referring to recursive etgas which has a straight forward solution by using the -R option). Something like this is needed, for example, in the case where we are using a third party library, including its headers, that could be installed anywh...

Problem when #import C++ Header File in iPhone/iPad Project

Hello ! I have a C++ class I would like to use in an iPhone/iPad project. I created this file in different ways (like with "New File" => C++) and the error is always the same. When I compile the project without having any #import (of the .h C++ class), it's ok. But as soon as I #import the header file in one of my header objective-c f...

Qt problem: No QProgressBar animation with minimum and maximum steps set to 0.

Hi, I have got a problem with my QProgressBar and I hope someone got an idea... I have created a progress dialog with a QProgressBar on my own. I set minimum and maximum steps to 0 so that the progress indicates my program is busy (the animation thing...). I show() this progress dialog and activated the Qt::WindowModal for this dialog....

Convert from C++ style printing to my_printf()

C++ purists may want to look away now. You will hate this. I have been given an open source windows console app that I am merging with a pre-existing, very old, very large windows app of my own. My old program started life as pure C though recently has been tweaked so that it can compile as C++. My program makes extensive use of a my_pr...

Debugging with AV Causes crash when LuaPriv checks enabled

This is the line where it crashes: if(!(PixelFormat = ChoosePixelFormat(hDC, &pfd))){ This is what errors it gives me on the SUA tool: 0x332D Error The application was denied access to an object. 0x331B Error Access was restricted to trusted users only. How do i fix these errors and prevent the usage of Application Verifier with...

'<function-style-cast>' : cannot convert from 'int' to 'CString'

This code was written in Visual Studio 2003, but now I compile it in 2008. int AFXAPI AfxMessageBox(LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0); if(iiRecd == SOCKET_ERROR || iiRecd == 0) { iErr = ::GetLastError(); AfxMessageBox(CString(iErr)); goto PreReturnCleanup; } In 2003, it works fine, but in 2008, it shows me...

Mono c# vs c++ in opengl game development?

Which of these languages is better for opengl game with primary platform linux? I would like if you compared them in performance and libraries support. ...

Microsoft .net, is it worth it?

So with Microsoft .NET, you get the advantage of language interoperability. But I've heard that this is slower than native applications. What if you only need one language? Then what are the advantages. I am a C and C++ programmer, and .net seems to be heavily tied with C#. Is this the case? And is dot net portable, or tied to windows? ...

convert std::string to LPCSTR with trailing or leading '\0'

Hi, How can I convert std::string to LPCSTR while preserving '\0' characters? I want to use the result on OPENFILENAME.lpstrFilter which requires the filter to contain '\0' as delimiters. std::string.c_str() seems to strip and trim '\0' Thanks in advance! ========================== (How do I properly add a comment to the responses...

Erasing an element from the vector during iteration c++

Hi, I wrote this method to find the minor of a sparse matrix: SpMatrixVec SparseMatrix::minor(SpMatrixVec matrix, int col) const{ SpMatrixVec::iterator it = matrix.begin(); int currRow = it->getRow(); int currCol = col; while(it != matrix.end()) { if(it->getRow() == currRow || it->getCol() == currCol){ ...

When is it appropriate to use static (over unnamed namespaces) in C++?

Hi, I have been reading articles about unnamed namespaces the whole day, most articles explained when you should use unnamed namespaces over the static keyword. But I am still left with one big question when is it appropriate to use static? After all it is not completely deprecated, what about header files with static functions should I...

Operator overloading and namespaces

Possible Duplicate: Where should non-member operator overloads be placed? While browsing on SO, I often find questions or answer that involves overloading/defining a std::ostream& operator<<(std::ostream& os, const Foo& foo) or a Foo operator+(const Foo& l, const Foo& r). While I know how and when (not) to write these operato...

gSOAP does **not** close sockets ??

Hi all, I've an issue with gSoap - it's not closing the socket.. Here's the situation: the application is working fine, but when I call "reload" function, it cannot reconnect.. Here's a piece of code: soap_destroy( &m_soapObj ); soap_end( &m_soapObj ); soap_done(&m_soapObj); sleep(1); soap_init(&m_soapObj); //m_ptrThis should be in...

c++ cast vector<Inherited*> to vector<abstract*>

Hi! class Interface{}; class Foo: public Interface{}; class Bar{ public: vector<Interface*> getStuff(); private: vector<Foo*> stuff; }; how Do I implement the funtion getStuff() ? hope the question is clear.. Thanks! ...

Linking to wrong library version in a C++ application

I'm troubleshooting a C++ binary on RHEL/CentOS 5, which has problems with the openssl shared libraries. I don't do much C/C++ programming, and I'm having trouble finding the root issue. What seems to be going wrong is that the application is linking to specific versions of libcrypto and libssl (0.9.8), instead of the symlinked paths of...