c++

(Non) Static Object in Loop

Hi, In a book there is an example about static/non-static objects. char buf[MAX]; long count=0; int i=0; while(i++<=MAX) if(buf[i]=='\0') { buf[i]='*'; ++count; } assert(count<=i); It is said that sometimes the code will write past the end of the buf array into count and make the assertion to fail. And then te...

Why does a struct consisting of a char, short, and char (in that order), when compiled in C++ with 4-byte packing enabled, come to a 6-byte struct?

I thought I understood how C/C++ handled struct member alignment. But I'm getting strange results for a particular arrangement in Visual Studio 2008 and 2010. Specifically, I'm finding that a struct consisting of a char, short, and char is compiled into a 6-byte struct, even with 4- or 8-byte packing enabled. I am at a loss as to why th...

Ensure multiset is reordered when objects change

I have a multiset with a custom predicate function, e.g multiset<MyClass *,MyCompFunc> where MyCompFunc looks at an attribute on the MyClass objects. During the progress of the application, the objects might change in a way that should cause them to be reordered. What's the correct way to get the multiset to become reordered when this h...

Easiest porting path from OpenGL Performer?

I have an existing program written in OpenGL Performer. Because new licences aren't available and the existing code base is old and poorly documented I was thinking about going through, fixing up the code (eliminating warnings and other bad programming practices). As part of this process I was thinking about switching the rendering ove...

C++ Access a member of a class from the pointer of a vector of the class

Sorry but this is really confusing me and I know the answer is staring at me in the face and I can't figure it out. Could someone take a look? Its for a Airline Reservation System school project. This function takes in the Flight Number, capacity, the count of the number of flights, and the vector containing all of the flights as argume...

Is it possible to "constify" a field of `std::pair` without hacks?

In C++, the compiling the following code: std::pair <int, int> x; static_cast <std::pair <const int, int>*> (&x); gives an error: error: invalid static_cast from type ‘std::pair<int, int>*’ to type ‘std::pair<const int, int>*’ I more or less understand why it happens, as cv-qualifying a type in a template parameter list can, in pr...

Problem with header files & c++ files

Hi, I'm creating a minimal circle-circle physics engine in a static library, and I've came across a problem. I have a header file for object manipulation, one of the variables is the objects position. The position variable is declared in bpObject.h, and I have a void function, SetPosition(), that accesses the current position and sets ...

Communication model: C++ and Java

Pals, I have a requirement to establish a communication channel between C++ and Java layer of my application for the exchange of objects and their properties. I have got the following options: XML / SOAP Postgre SQL Can you please advice me the Pros & Cons on these. Please share your experiences on the implementation complexities. ...

Any library providing common used structures and algorithms for FUSE

Hi, I am going to write a file system prototype by using FUSE. Are there any (additional) well implemented libraries besides FUSE that can provide some common file system optimizing functions like dir cache, journaling, lookup table, atomic ops and etc. It should be better written in C. By the way, I am going to implement it on OSX an...

Ho to use the correct unmanaged dll according CPU architecure? (32 / 64bits)

I have to use a c++ dll from an asp .net site. The site will be hosted on both 32 and 64bits environments. I have a 32 and 64 bits version of the unmanaged dll. How do I import the methods from the correct one according the current server architecture? EDIT Like some one posted, this could be handled as a deployment problem. My concern...

Best way to initialize class's inherited member var of type std::array?

Entity has a member var of type std::array. Student inherits from Entity, and will need to initialize the std::array member var it inherited. Below is the code I'm using to do this, but it involves casting a brace-enclosed list to std::array. I'm not sure this is the correct or optimal way to do this. Using a brace-enclosed or double...

Weird outputs with simple Arithmetic C++

If I give this program a string as in input it gives me some very strange outputs. How do I go about handling this? I'd like it to simply state that there was an error on the consul. #include <cstdlib> #include <iostream> using namespace std; int main() { cout << endl; cout << "Homework (out of 70 pts): " ; int HW ; ...

Is return atomic and should I use temporary in getter to be thread safe?

Is it necessary to use a temporary here to be thread-safe? int getVal() { this->_mutex.lock(); int result = this->_val; this->_mutex.unlock(); return result; } I'll give you disassembly of simple RAII test function int test() { RAIITest raii; //let's say it's a scoped lock return 3; } { 0...

class method error in c++

I am getting an error when I declare a class: #include <iostream> #include "testing/test.h" #include <string> using namespace std; int main(void) { test links; string content="this is an string"; links.getcont(content); } test.h #ifndef TEST_H_ #define TEST_H_ #include<string> using namespace std; class test { ...

Is there a way in C++ to render a class' interface private to all classes except a few?

I am writing a B-link tree and its attendant sub classes like a data page class and a node class etc. I was wondering is there a way to protect the public interfaces of the nodes and pages such that only the b-link tree class itself can access them, WITHOUT simultaneously exposing the private methods of the pages and nodes to the b-link...

C++ output with webpages

Is it possible to have a c++ program like this... #include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; } And have it's output on a webpage like this... <html> <head> <title>C++</title> </head> <body> <div src = "cpp.exe"></div> </body> </html> ...

C++ Extern / Multiple Definitions

I am trying to interface to Ada in C++ using externs. What is the difference between these two implementations? Implementation A namespace Ada { extern "C" { int getNumber(); int index; int value; } } Implementation B namespace Ada { extern "C" { int getNumber(); } exte...

Advantages of implementing a front-end over linking against a library

I want to write a C++ program that plays MP3. Among available MP3 decoding libraries, I chose mpg123. I noticed that, besides being able to link against libmpg123 and make the necessary function calls in my code, the library includes a back-end/front-end interface that enables me to communicate with it's executable, and thus not having ...

typedef inheritance from a pure abstract base

Edit: Found duplicate I've whittled down some problem code to the simplest working case to illustrate the following: my typedef in a pure abstract base class is not being inherited by the derived class. In the code below I'd like to inherit the system_t typedef into the ConcreteTemplateMethod: #include <iostream> // pure abstract te...

Can a std::map value object contain a reference to the corresponding key?

Essentially, what I'd like is for the value object to maintain a reference to the corresponding key object, because there's some useful information in there, which would be nice to access via the value object. What I'm attempting to do may just not make sense, but consider the following: class key { // ... Various members ... f...