c++

Difference between -Wconversion between gcc and g++

Consider the following test program: static void func(int a) { } int main() { unsigned int b = 42; func(b); return 0; } Compiling it with gcc: lol@mac:~/projects$ gcc -Wconversion testit.c testit.c: In function âmainâ: testit.c:11: warning: passing argument 1 of âfuncâ as signed due to prototype lol@mac:~/projects$ ...

VS2005 C++ compiler problem including <comdef.h> in MFC application

I am having some trouble converting an old project from VS6 to VS2005. At one place in the code it uses the type variant_t so it includes comdef.h for this purpose. comdef.h then includes comutil.h which generates these errors for me: c:\program files\microsoft visual studio 8\vc\include\comutil.h(978) : error C2535: '_variant_t::_varia...

[Borland C++ Builder 5] DynamicArray throws OutOfBounds exception

Hi all, I know this may sound strange, but yes, it's 2009 and I need to write small application using BCB5 :) The problem is that DynamicArray throws OutOfBound exception when trying to expand it from within worker thread. I have global variable, let's say DynamicArray<double> X; In main thread I check the length of array and I g...

C++ stdio::rename(); synchronous?

I was just wandering if stdio::rename() function call is fully synchronous. So is the file immediately after return from the function call available under new name or it might take some time (some miliseconds) until this happens? I am investigating an irritating timing bug and suspect that the latter case happens. My software runs on Wi...

excelApp.CreateDispatch() returns a zero value : failure

I have the following piece of code in Visual C++ 2005 : : class _Application:public COleDispatchDriver {....}; _Application excelApp; excelApp.CreateDispatch((LPCTSTR)_T("Excel.Application"))) But the call to excelApp.CreateDispatch((LPCTSTR)_T("Excel.Application"))) returns a zero value indicating a failure . Could you please te...

reference variable

In some text it is given that we can't assign constant values to a reference variable. When I executed such a program I could do it. Is there any condition we can't assign a constant value to a reference variable? ...

Keeping the GUI separate

I have a program that (amongst other things) has a command line interface that lets the user enter strings, which will then be sent over the network. The problem is that I'm not sure how to connect the events, which are generated deep inside the GUI, to the network interface. Suppose for instance that my GUI class hierarchy looks like th...

Strange behavior in constructor

Hi, I have a class made up of several fields, and I have several constructors. I also have a constructor that doesn't take any parameters, but when I try to use it: int main { A a; } The compiler generates an error, while if I use it like this: int main { A a(); } It's ok. What's that? Thank you ...

Is there any guarantee of alignment of address return by C++'s new operation?

Hi, Most of experienced programmer knows data alignment is important for program's performance. I have seen some programmer wrote program that allocate bigger size of buffer than they need, and use the aligned pointer as begin. I am wondering should I do that in my program, I have no idea is there any guarantee of alignment of address r...

Mysterious relative path library dependency

After loading an existing MFC application in Visual Studio 2008, I am left with one linking error: LINK : fatal error LNK1104: cannot open file '..\..\xpressmp\lib\xprm_rt.lib' I have looked "everywhere", but I can't figure out where the relative path is set. The lib file is located in C:\xpressmp\lib, and I have added this directory ...

How to use swig to generate php interface for c++ so

Ok, I have tried a 100 things and i can not get my so file to interface with php using swig. I can generate the files, then i had to compile zend and link with that to make the so but it keeps seg faulting on load now. Can some one please walk me though how to use swig to generate a php interface for a c++ so as the one on there site i...

Simple object-oriented 2D graphics framework for use in Visual C++?

We're building a method of connecting components visually via a GUI in a Visual C++ application (MFC). Simple things like clicking on boxes and drawing lines between those that are connected, and storing information on them. The problem is that we're making all this by ourselves from the ground up in GDI and it quickly becomes a heck of ...

What are the common misuse of using STL containers with iterators?

What are the common misuse of using STL containers with iterators? ...

VC++ Resource Editor Problem?

I have a working C++ project on VS2005, I made a small change which causes a problem and I dont know what is it and how to resolve, I added a new string entry in the resource file using the VS2005 RC editor (the default one in VS2005) but after compilation I get two compilation errors Error 22 error RC2135 : file not found: BEGIN f:...

C++ overloaded function

Maybe Im to tired, but this seems to be a vary basic question. Suddenly my inheritance chain stopped working. Writing a small basic test application proved that it was me that was wrong (so I cant blame the compiler). I have a base class, with the default behavior in a virtual function. A child class derives from that and changes the be...

Is there a way to monitor heap usage in C++/MacOS?

Hello, I fear that some of my code is causing memory leaks, and I'm not sure about how to check it. Is there a tool or something for MacOS X? Thank you ...

GCC 4.0: "no matching function to call" in template function

Hi, I am wondering why the following contrived example code works perfectly fine in Visual Studio 2005, but generates an error in GCC ("no matching function to call" when calling Interpolate() as shown below). Also, how do I work around this? It seems that the error message is just a generic message because GCC did not have a more spe...

How to convert a float to a string regardless of regional settings?

My product is targeted to a Portuguese audience where the comma is the decimal symbol. I usually use CString::Format to input numbers into strings, and it takes into account the computer's regional settings. While in general this is a good approach, I'm having problems in formatting SQL queries, for instance: CString szInsert; szInsert....

Adding resource file to VC6 dll

I have a number of VC 6.0 projects (dsps) which build into dlls which don't have resource files. Any idea how to add resources into an existing project? The project is due for a major release shortly and I want to add a fileversion to those dlls currently lacking one. The dlls will be recompilied before release so I'm just trying to mak...

What is the nicest way to find a specific string in vector?

For instance. I have some structure: s_Some{ std::string lable; s_some_junk some_junk; }; And a vector: std::vector<s_Some> mSome; And then I fill this vector with a lot of s_Somes. I need to find an iterator for a single s_Some in this vector, which has a specific lable. So far I just iterate through all of this junk and mat...