c++

Locating etc and share directories on Linux

I'm writing a program for Linux in C++, and I need to store some additional data, such as images. Stuff like that is usually in /usr/share on Linux. The user can decide where to install the software (I'm using CMake), thus I should either use /usr/share, /usr/local/share, /home/theuser/somefolder/share or whatever, depending on where he...

Problem using abstract factory..

Hi, I am using an abstract factory to create user interface components such as dialogs. The abstract factory used is returned from a currently selected generic "INode" which is the base class for several different types of node. So for instance, if I want to add a new node of the same type as the selected node, the scenario goes someth...

std::tr1::mem_fn return type

I want to put the result of this: std::tr1::mem_fn(&ClassA::method); Inside a variable, what is the type of this variable ? That will look something like this: MagicalType fun = std::tr1::mem_fn(&ClassA::method); Also, what is the result type of std::tr1::bind ? Thank you ! ...

Using g++ to compile, how do I point it to other .h files?

I'm trying to compile a .cpp + .h file that includes newmat.h and tinyxml.h - I have libnewmat.a and libtinyxml.a in the same directory as my .cpp and .h files and I'm running g++ -lnewmat -ltinyxml test.cpp test.h but still getting newmat.h and tinyxml.h not found at the beginning of compilation. I'm obviously a total c++ newb becau...

Relearning C++ and a typedef issue

So, it's been 5 or 6 years since I've used C++ for a large project, and about half a year since I last had to deal with small/trivial C++ programs and the C++ runtime in general. I've decided I want to re-learn the language, primarily because it might prove very relevant for an upcoming project at work. I've been working mainly with C ...

Can boolean operators be used with the preprocessor?

I wondering if it possible to have a preprocessor OR or AND statement? I have this code where I want to run under _DEBUG or _UNIT_TEST tags(?). What I want is something like the following: #if _DEBUG || _UNIT_TEST //Code here #endif If this is not possible, is there a workaround to achieve the same thing without having to duplicat...

How to be in the comfort zone in C++/Java at the same time

Hi, This is obviously a subjective question. But I think many people would relate to this. One of the main problems I face as a developer is that I can only keep one language (Java or C++) in my head. What I mean is that if I have to work on 2 projects: 1 Java and 1 C++ simultaneously then I have a very bad time managing the two. I us...

Why would GLU crash at this spot?

I have found that my application crashes with a null reference exception right here in sweep.c in GLU source code: static void ConnectLeftVertex( GLUtesselator *tess, GLUvertex *vEvent ) /* * Purpose: connect a "left" vertex (one where both edges go right) * to the processed portion of the mesh. Let R be the active region * containi...

offsetof function in c++

here is code #include <stdio.h> #include <stddef.h> struct mystruct { char singlechar; char arraymember[10]; char anotherchar; }; int main () { printf ("offsetof(mystruct,singlechar) is %d\n",offsetof(mystruct,singlechar)); printf ("offsetof(mystruct,arraymember) is %d\n",offsetof(mystruct,arraymember)); printf ("offset...

Where in the C++ Standard does it say ::delete can change lvalues?

I ran into my first compiler that changes the lvalue passed to ::delete, but doesn't zero out the lvalue. That is the following is true: Foo * p = new Foo(); Foo * q = p; assert(p != 0); assert(p == q); ::delete p; assert(p != q); assert(p != 0); Note that p is not zero after the delete operation, and it has changed from it's o...

Calculate vertices of a circle

Hey guys, I am having a simple program, it draws a circle :/ This works fine... for (k = 1; k < n+1+1; k++){ vertices[k].color = GU_COLOR( 0.0f, 0.0f, 1.0f, 0.0f ); vertices[k].x = cos_d( 360 - ((k-1) * dstep) ); vertices[k].y = sin_d( 360 - ((k-1) * dstep) ); vertices[k].z = 0.0f; } ... //Now draw it sceGumDrawArray(GU_TRIANGLE_FAN...

Does OpenSSL has any event callback function for 'Read' data?

I was looking for event callback function when OpenSSL has incoming 'Read' data. Does OpenSSL has this kind of function? If yes, could you please show me some example code please? I'm thinking to write a simple wrapper for my application. This wrapper will make a callback when data arrive. My initial thought would be create a thread loo...

Installing Rcpp in R 2.10 on Ubuntu

I'm trying to install Rcpp on Ubuntu 10.04 and getting this error (which implies that it doesn't exist): > install.packages("Rcpp") Warning in install.packages("Rcpp") : argument 'lib' is missing: using '/home/vadmin/R/i486-pc-linux-gnu-library/2.10' Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘...

Android JNI System.loadLibrary not needed?

Hey everyone, I need your help to add some insight into JNI on Android. I've been looking at the /libcore/x-net package in Android and notice that Apache Harmony is the default provider for SSL functionality (using OpenSSL). Everywhere I've found on the internet says that when you use JNI in Android you must load the native code by us...

I would like to do some programming stuff during summer, what do you recommend?

Preferable C/C++, Python or Java. I'm tired of doing simple and silly applications. I would like to start or help in a big project, but I don't know how to do it and what to do. Any idea? ...

[STL] Enjoying Both Worlds: vector With insert/erase efficiency of list

I need a container that gives me a fast indexer and can also be very efficiency in arbitrary insertion and deletion operations (meaning at any position of the container). I remember reading about such container that uses buckets but I can't seem to find it or retrace the steps that lead me to it (I will start using the bookmarks, prom...

Visual Studio: Inconsistency in method header

I have a method in C++: HRESULT Foo(const ULONG bar, const ULONG baz, ODP& odp) ODP is typedef'd to unsigned short. When I call this method, I get a VS runtime check error when the calling method ends: "The stack around odp is corrupted." When I look at the method being called, and hover my mouse, VS pops up this description: Foo(c...

C++, monitor for keyboard input

Hi, I'm brushing up on my general programing skills and I've come across a snag. I'm writing a program that simulates a colony of bunnys. Once this program starts it is autonomous, however, at any point the user should be able to press the 'k' key to cull the population by half. I can't think of a way to do this without pausing the progr...

Thread class memory allocation oddity on an embedded platform

I am running into a strange issue I've been able to track down somewhat but I still can't see the cause. Maybe someone here can shed some light? I'm running on a PowerPC processor on top of VxWorks 5.5 developing in C++ with the PPCgnu604 toolchain. I have a class like so: class MyClass { public: void run( void ); private: ...

Control flow syntax in c++

With the following c++ example(indention was left out in purpose). if(condA) // if #1 if(condB) // if #2 if(condC) // if #3 if(condD) // if #4 funcA(); else if(condD) // else #1 if #5 funcB(); else if(condE) // else #2 if #6 funcC(); else // else #3 funcD(); else if(condF) //...