c++

Using Java from C++

As a C++ developer, I occasionally come across Java libraries like iText, Batik, JasperReports, and JFreeChart. In each case, equivalent cross-platform C++ libraries seem to be much less mature, much more expensive, or unavailable. Is it practical to use these Java libraries from my C++ app for reporting, charting, and similar? If so,...

Comparing a variable to a range of values in C++

In mathematics, the notation 18 < age < 30 denotes that age must lie between the values 18 and 30. Is it possible to use this kind of notation in the if statement? For example, I've tried executing if(18 < age < 30) and I get wierd output, so it's not quite right. Is there a way to do this or so I simply have to write if(age > 18) b...

Random and negative numbers

Hello, I have to generate numbers in range [-100; +2000] in c++. How can I do this with rand if there is only positive numbers available? Are there any fast ways? ...

C++ Program quits unexpectedly, how do I debug this with gdb?

Hi Everyone, I am writing a program that runs some unit tests on code that that been written by my colleagues. I am using the Google C++ testing framework. I run a function that spawns 3 threads, and then runs for 30 seconds. After it runs, the program exits with status 0. This is not the expected behavior, obviously. I know it doesn't ...

How to create an array to hold C++ classes (not instances) to be used iteratively in a template function.

I need to repeatedly make calls to a template function with different classes defined elsewhere in the code, like so: MyTemplateFunction<ClassOne>( &AnotherTemplateFunction<ClassOne> ); MyTemplateFunction<ClassTwo>( &AnotherTemplateFunction<ClassTwo> ); MyTemplateFunction<ClassThree>( &AnotherTemplateFunction<ClassThree> ); MyTemplateFu...

Deduce return type of operator/function for templates

Is something like this possible? // We can even assume T and U are native C++ types template<typename T, typename U> magically_deduce_return_type_of(T * U) my_mul() { return T * U; } Or would somebody have to hack up a return_type struct and specialize it for every pair of native types? ...

Convert axes coordinates to pixel coordinates

I'm looking for an efficient way to convert axes coordinates to pixel coordinates for multiple screen resolutions. For example if had a data set of values for temperature over time, something like: int temps[] = {-8, -5, -4, 0, 1, 0, 3}; int times[] = {0, 12, 16, 30, 42, 50, 57}; What's the most efficient way to transform the dataset...

Using size of one array in another array

// sizeofarray.cpp #include <iostream> template <typename T,int N> int size(T (&Array)[N]) { return N; } int main() { char p[]="Je suis trop bon, et vous?"; char q[size(p)]; // (A) return 0; } I heard that an array size in C++ must be a constant expression. So char q[size(p)] is invalid, am I right? But I got no errors when...

main cant be void

Possible Duplicate: does c++ standard prohibit the void main() prototype? Why is bloodshed c++ not letting me do void main()? its not much of a problem, but Im still curious. ...

How to be sure if a processor is 32bits or 64bits ? Are dual core processors 32 or 64 bits ?

Having a Macbook Pro with windows installed thanks to bootcamp, I have several questions: Under windows, I see that processes only use 50% maximum of the CPU charge, is that because the processor is a dual core and because the process is not multi-threaded ? Should I install windows xp version 64 bits instead, to have better performanc...

Inserting a "£" sign in an output string in C++

I have the following code: cout << "String that includes a £ sign"; However, the £ sign is not being recognised by the compiler, and instead an accented u is being displayed. I'm able to insert one using the following method: cout << "String that includes a " << char(156) << " sign"; where 156 is the ASCII code of the £ sign. Is th...

Creating clone of an object not working with virtual base class

#include<iostream> using namespace std; class Something { public: int j; Something():j(20) {cout<<"Something initialized. j="<<j<<endl;} }; class Base { private: Base(const Base&) {} public: Base() {} virtual Base *clone() { return new Base(*this); } virtual void ID() { cout<<"BASE"<<endl; } }; class Derived ...

why is RAND_MAX a macro in C++?

Why is it not a const? I think this is not a clear C++ way. Perhaps there is a more C++ way to generate random numbers, is there? ...

C++, unmanaged, class, members: How (if at all) can I list all the members in a class?

Possible Duplicate: Iterate through struct variables. So I have a header file and a code file. The class is representation of a View that will be queried from stored proc. For each col. in view there is one data member in class. Currently in code we have something like this: Load( Reader reader) { m_col1 = reader("m_col1...

Differences between tr1::shared_ptr and boost::shared_ptr?

Are there any difference between tr1::shared_ptr and boost::shared_ptr? If so, what? ...

Removing external dependencies to MFC DLL project

Im developing a MFC DLL project in VS2008. The dll compiles OK and I can call it fine from an GUI exe that a contractor has developed for me. Visual C++ Redistributables are required to be installed for my dll (and maybe the exe which is developed in C++ too) Another company wants to licence my dll to use with their C++ exe. They have ...

C++ Struct initialisation problem

Hello, This c++ code is working fine , however memory validator says that I am using a deleted pointer in: grf->filePath = fname; Do you have any idea why ? Thank you. Dirloader.h // Other code class CDirLoader { public: struct TKnownGRF { std::string filePath; DWORD encodingType; DWORD ...

C++ - Clutter 1.0 - calling function from thread causes segfault

Hello! I am struggling with calling a clutter function from an extra thread. I use boost::thread for threading and the clutter library 1.0. To be specific, the thread contains a looped function that emits boost::signals2::signal with parameters of x and y coordinates every once in a while. That signal is connected to a function that ha...

create a simple dll file with JNI

Im trying to create a simple dll file.Im following the tutorial http://java.sun.com/docs/books/jni/html/start.html when i try to compile the c program i get following error : Warning W8057 HelloWorld.c 10: Parameter 'env' is never used in function Java_He lloWorld_print Warning W8057 HelloWorld.c 10: Parameter 'obj' is never used in ...

Is it possible to use attributes in unmanaged code?

I have an unmanaged C++ application (unmanaged meaning: not using anything of the the fancy .Net stuff). I want to extend it with some meta information, and it looks like I could use the concept of attributes. What I actually try to achieve is the following. Starting from something a simple class like this: class Book { public: ...