c++

Do pthread Mutexs work across threads if in shared memory?

I found this: http://stackoverflow.com/questions/2284730/fast-interprocess-synchronization-method I used to believe that a pThread mutex can only be shared between two thraeds in the same address space. The question / answers there seems to imply: If I have two separate proceses A & B. They ahve a shared memory region M. I can put a p...

Running function from an unmanaged dll inside a C# thread.

Here's my problem: I have an unmanaged dll that I made.I'm calling one of this dll's functions in my C# code, using PInvoke. Under certain conditions, in the dll function, I want to be able to terminate the thread that is running the function.How would I achieve that? Sorry if it is a stupid question, but I'm a total noob when it comes ...

string conversion between UTF-8 representation and unicode representation

How to design an algorithm to convert a UTF-8 string to a unicode string? ...

Class structure for an inventory control system

As an exercise in good OO methods and design, I want to know what is a good way to model inventory control in a company. The problem description is a. A company can have different types of items, like documents (both electronic and physical), computers etc which may further have their own sub types. b. The items can be kept in a...

Boost.Program_options fixed number of tokens

Boost.Program_options provides a facility to pass multiple tokens via command line arguments as follows: std::vector<int> nums; po::options_description desc("Allowed options"); desc.add_options() ("help", "Produce help message.") ("nums", po::value< std::vector<int> >(&nums)->multitoken(), "Numbers.") ; po::variables_map v...

Need to traverse matrix-like graph in expanding concentric squares...

Ok, I've a data structure that consists of a matrix of linked nodes, lets say 10x10. I would like to be able to choose any of these nodes arbitrarily, and - from there - process a number of the surrounding nodes following the pattern of expanding concentric squares (I used less nodes below for illustration purposes). As far as specifics ...

First while loop's first iteration always fails to take input. 2+ loops work fine.

The bug starts at cin.getline ( string, 25, '\n' ); or the line below it (strtod). If I use cin, it works, except I cannot quit out. If I type anything that's not a double, an infinite loop runs. Need help. Basically, the first iteration runs, does not ask for input, so the user gets the math questions wrong. The second iteration works f...

How do I strong name a C++ assembly in VS2008?

I have no experience developing C++ on Windows, but I am a C# developer. I have a wrapper around some native DLLs that is written in C++. (A LGPL project)). I was to use this from a strong named assembly. How do I set up the strong naming of the C++ assembly? There is no 'Signing' properties tab available as there is in C# projects....

printf question with a const char* variable

Hi, I am stuck in a printf problem. I would appreciate if I can get some help here: In the below code, I can see the font family get displaced correctly in first printf(), but if I set it to variable, i only get an empty string. How can I put it in a variable and have the right values? I just don't want to type 'font.family().family().s...

Error #1006 value is not a function in C++ code compiled by Alchemy

I'm trying to port a big library to Alchemy. I've run into something that looks like an Alchemy bug. I have a class with a static member. There's a static function that uses it. Something like this: In foo.h: class Foo { static Bar m_pBar; static void doSomething (int a); } In foo.cpp: Bar Foo::m_pBar; void Foo::doSomething...

PInvokeStackImbalance C# call to unmanaged C++ function

After switching to VS2010, the managed debug assistant is displaying an error about an unbalanced stack from a call to an unmanaged C++ function from a C# application. The usuals suspects don't seem to be causing the issue. Is there something else I should check? The VS2008 built C++ dll and C# application never had a problem, no weird ...

OpenGL texture mapping on sides cube using GL_QUADS

I am trying to map a different texture on each side of a cube using a GL_QUADS. My first problem is that I cannot even get a texture to display on the side of a GL_QUADS. I can however get a texture to display using GL_TRIANGLES but I do no understand how to draw things very well using triangles and I want to use QUADS. I also can only u...

Checking ignore() for values

When you use ignore() in C++, is there a way to check those values that were ignored? I basically am reading some # of chars and want to know if I ignored normal characters in the text, or if I got the newline character first. Thanks. ...

C++ inheritance, base functions still being called when overriden

I have the following two classes, one inherits from the other Class A{ void print(){cout << "A" << endl;} } Class B : A{ void print(){cout << "B" << endl;} } Class C : A{ void print(){cout << "C" << endl;} } Then in another class I have the following: vector<A> things; if (..) things.push_back(C()); else if (..) things.push...

SSPI Negotiate not found

Hi! I'm using Windows XP Pro SP3. I want to use SSPI functions in my code. I compiled my code, no error. I set the security package to be used to Negotiate, which is recommended. When I start my program, Negotiate cannot be used because it can't be found. So, I tried "Kerberos" instead, and same error: the security package cannot be f...

Checking for an empty file in C++

Is there an easy way to check if a file is empty. Like if you are passing a file to a function and you realize it's empty, then you close it right away? Thanks. Edit, I tried using the fseek method, but I get an error saying 'cannot convert ifstream to FILE *'. My function's parameter is myFunction(ifstream &inFile) ...

Follow-up. Is return reference to x++ defined?

I recently asked the question http://stackoverflow.com/questions/2380803/is-the-behavior-of-return-x-defined The result was about what I expected, but got me thinking about a similar situation. If I were to write class Foo { ... int x; int& bar() { return x++; } }; Where bar now returns an int reference, is this behav...

Are the subscripts for three-dimensional arrays strictly defined?

Let's say I declare this: int [a][b][c]; Does a stand for the level/page, b the row and c the column? Or can it be anything I want it to be i.e. a stands for column, b stands for page, and c stands for row (since data is just data and a cube can be abstracted any way)? ...

Difference between i++ and ++i in a for loop

Possible Duplicates: Incrementing in C++ - When to use x++ or ++x? What is the difference between for (int i = 0; i < MAX; i++) { //...do something } and for (int i = 0; i < MAX; ++i) { //...do something } ? ...

Java's "public static final Object" in C++

What would be the equivalent of this in C++ of the following snippet. I am in the process converting parts of an java application to C++. Here is that java class snippet: class container { Public static final Object CONTAINER_FULL = new Object { public boolean equals(Object other) { // ... } String toString() ...