c++

Partial ordering with function template having undeduced context.

While reading another question, i came to a problem with partial ordering, which i cut down to the following test-case template<typename T> struct Const { typedef void type; }; template<typename T> void f(T, typename Const<T>::type*) { cout << "Const"; } // T1 template<typename T> void f(T, void*) { cout << "void*"; } // T2 int main(...

Developing a static source code analysis tool for proprietary API?

There is a proprietary API that is built on top of C++. So it uses all the features of C++ and then has its own APIs. There are some APIs that function exactly the same as C++ API (like for malloc there is Stralloc), these APIs are provided for performance reasons. Though there are many static code analyzers available for C++, we cannot...

MFC: retrieve button ID programmatically

I have a CButton object called mouseCtrl, and in the DoDataExchange function, I have the following: DDX_Control(pDX, IDC_MCCHECK, mouseMode); Somewhere else in my program, I would like to be able to call a function/method of mouseMode so that I can retrieve the IDC_MCCCHECK id macro properly. Is there a function in MFC that can allow ...

TCPL 5.9.9 (C++): Where would it make sense to use a name in its own initializer?

This is a question from the most recent version of Stroustrup's "The C++ Programming Language". I've been mulling this over in my head for the past couple days. The only thing I can come up with, (and this is probably incorrect) is something like this: int* f(int n) { int* a = &a - n * sizeof(int*); return a; } My intent is to g...

Avoiding null pointer exceptions in a large c++ code base

I have inherited a large c++ code base and I have a task to avoid any null pointer exceptions that can happen in the code base. Are there are static analysis tools available, I am thinking lint, that you have used successfully. What other things do you look out for? ...

Deterministic builds under Windows

The ultimate goal is comparing 2 binaries built from exact same source in exact same environment and being able to tell that they indeed are functionally equivalent. One application for this would be focusing QA time on things that were actually changed between releases, as well as change monitoring in general. MSVC in tandem with PE ...

Problem with iterating over a lots of images in OpenCv with mac os

I'm trying to iterator over some directories containing approximately 3000 images. I load the image. If the image is loaded I release it. That is the smallest program that I can write to reproduce the error. After loading and releasing 124 images the program stops loading images. I think this a memory issue but I don't understand what...

Reading data from a file

I'm doing an exercise where I store coordinates into a .txt file called mydata, and then read it back from that file. However, I"m having trouble reading it back. code: #include "std_lib_facilities.h" // Classes---------------------------------------------------------------------- struct Point{ Point(int a, int b):x(a), y(b) {}; Poin...

Programmatically compute the start time of a process on Windows

Hi, I'm writing c/c++ code on Windows using Visual Studio. I want to know how to calculate the start time of my process effectively. Can I just use gettimeofday()? I've found the following code from google but I don't understand what it's doing really : int gettimeofday(struct timeval *tv, struct timezone *tz) { FILETIME ft; uns...

string::size_type instead of int

const std::string::size_type cols = greeting.size() + pad * 2 + 2; Why string::size_type? int is supposed to work! it holds numbers!!! ...

How to create project dependencies in netbeans (c/c++ plugin)

As I work on a c++ application, I realize I am making a lot of classes and functions that could be used in other projects. So I'd like to put all this code in a separate net beans project that can be "included" into other projects. (with code completion etc) I've tried creating a new "static library" project, then I added the project to...

Multiple Symbol Reference problem in shared library of a factory design pattern

Hello, I am trying to write a C++ implementation of factory design pattern. I would also like to do it using shared objects and dynamic loading. I am implementing a function called new_animal() which is passed a string. If the string is "dog", then it needs to see if a class dog is registered in shared object and create a dog object...

How do I open a new console window for a Visual C++ console application?

What I want to do is something like this: ConsoleWindow1.Print("1"); ConsoleWindow2.Print("2"); When I run the program, two console windows pop up and one gets printed with 1 and the other gets printed with 2. Is there a simple way of doing this? ...

Standard library sort and user defined types

If I want to sort a vector of a UDT by one of two types of variables it holds, is it possible for the standard library sort to do this or do I need to write my own sort function. For example if you had struct MyType{ int a; int b; }; vector<MyType> moo; // do stuff that pushes data back into moo sort(moo.begin(), moo.end()) // but...

Practical point of view: Why would I want to use Python with C++ ?

I've been seeing some examples of Python being used with c++, and I'm trying to understand why would someone want to do it. What are the benefits of calling C++ code from an external language such as Python? I'd appreciate a simple example - Boost::Python will do ...

Determine compile-time existence of include files in C++

I'm trying to write some portable C++ library code that will initially rely on Boost.Regex, and then move to TR1 as compilers support it, and eventually to the C++0x specification after things get moved from the std::tr1 namespace to std. Here is some pseudo-code for what I'd like to do with the preprocessor: if( exists(regex) ) // c...

How to receive dynamic length data from a message queue?

I have to send and receive dynamic data using a SysV message queue for a university project. The length of the data is transmitted in a separate message, size is therefor already known. And this is how I try to receive the data. I have to admit that I'm not a C++ specialist, especially when it comes to memory allocation. struct { ...

sqlite db2 error for symbian

i am getting error for statement TInt err1 =stmt.Prepare(db,_L("INSERT INTO MyContacts(ServerContactID,UserName,FirstName,LastName,Country,IsBlocked,RequestStatus,MarkForDeletion) VALUES(:ServerContactID,:UserName,:FirstName,:LastName,:Country,:IsBlocked,:RequestStatus,:MarkForDeletion)")); for this statements if i print err1 i am g...

scanf() causing strange results

I have a piece of code that presents an interesting question (in my opinion). /*power.c raises numbers to integer powers*/ #include <stdio.h> double power(double n, int p); int main(void) { double x, xpow; /*x is the orginal number and xpow is the result*/ int exp;/*exp is the exponent that x is being raised to */ printf(...

link error when using boost library on MacOSX

I have created a XCode project and I have added "/opt/local/include/boost" to Header Search Path and "/opt/local/lib" to Library Search Path But I still have this error: boost::system::get_generic_category()", referenced from: __static_initialization_and_destruction_0(int, int)in main.o __static_initialization_and_destruction_0...