c++

How can i seperate Headers, classes and main functions in C++?

Please help me in separating the classes, headers and main() in the following program. I tried my best but there is problem. #include "stdafx.h" #include<iostream> #include<string> using namespace std; class player { public: string name; string type; void getdata() { cout<<"Enter the name of the Player : "<<endl; ...

C++ variable data being overwritten

Hi, Been a few years since I've written C/C++, and now I'm facing a problem I just cannot seem to solve on my own. Given the following struct: struct InputData { float diameter; float length; int vertIndex; struct InputData *parent; vector<InputData*> children; bool deadEnd; InputData(float dia, float lngt...

linking and using a C++ library with an Objective-C application

I'm writing a graphical application using Objective-C for the front end and C++ for the graphics processing and network communication. I read around on Apple's site looking for a way to link either a .dylib or .so with my C++ code in it to my Xcode project, but nothing seemed to work. I was able to get the project to reference it and lin...

How to circumvent Symbian naming conventions?

I'm about to write a C++ library that is to be used by a Windows application as well as on Symbian. Linux is not a current requirement but should generally be possible, too. For this reason I would like to use the STL/Boost naming conventions instead of Symbian's, which I think, are hard to get used to. This seems to already present a pr...

Detect compiler with #ifdef

I'm trying to build a small code that works across multiple platforms and compilers. I use assertions, most of which can be turned off, but when compiling with PGI's pgicpp using -mp for OpenMP support, it automatically uses the --no_exceptions option: everywhere in my code with a "throw" statement generates a fatal compiler error. ("sup...

read from file to array of structs within structs in C++

I have asked this question previously here and a similar question was closed. SO based on a comment from another user, I have reframed my question: In the first post, I was trying to read tha data from a file into an array with a struct.By using indata << p[i] and is >> p.fId, I was able to read values from data file into PersonId. No...

Comparing 2 graphs created by Boost Graph Library

This may be a rather novice or even wrong question so please be forgiving. Is there a way to compare 2 graphs created using the Boost Graph Library => with 1 graph created in memory and the 2nd loaded from an archive (i.e. 2nd was serialized out previously)? I don't see an operator== provided in BGL's documentation, but not sure if that...

How Operating System callbacks work.

Follow up question to: This question As described in the linked question, we have an API that uses an event look that polls select() to handle user defined callbacks. I have a class using this like such: class example{ public: example(){ Timer* theTimer1 = Timer::Event::create(timeInterval,&example::FunctionName); ...

How do i forward declare a class that has been typedef'd?

I have a string class that, unsurprisingly, uses a different implementation depending on whether or not UNICODE is enabled. #ifdef UNICODE typedef StringUTF16 StringT; #else typedef StringUTF8 StringT; #endif This works nicely but I currently have a problem where I need to forward declare the StringT typedef. How can I do this? I ca...

why >?= and <?= don't work in VC++?

why >?= and <?= don't work in VC++? but they work fine in gcc/g++ like: a>?=b; are they right usages? ...

How can I get an HDC object from a CDC object?

I have an object, dc, of type CDC and I'd like to get an HDC object. I read the MSDN documentation here, but don't really understand it. Can someone provide me with a brief example/explanation on how to do this? ...

Purpose of Trigraph sequences in C++?

According to C++'03 Standard 2.3/1: Before any other processing takes place, each occurrence of one of the following sequences of three characters (“trigraph sequences”) is replaced by the single character indicated in Table 1. ---------------------------------------------------------------------------- | trigraph | replacement | t...

C++ Socket Server - Unable to saturate CPU

I've developed a mini HTTP server in C++, using boost::asio, and now I'm load testing it with multiple clients and I've been unable to get close to saturating the CPU. I'm running on a 4-cpu box, and getting about 50% usage of one cpu, 20% of another, and the remaining two are idle (according to htop). Details: The server fires up on...

Is it a bad idea to use pointers as loop incrementers instead of the usual "int i"?

An example of this would be: char str[] = "Hello"; int strLength = strlen(str); for ( char * pc = str; pc < str + strLength; pc++) { *pc += 2; } Edit: Accounted for write-protected memory issue. ...

How to get a Win32 Thread to wait on a work queue and a socket?

I need a client networking thread to be able to respond both to new messages to be transmitted, and the receipt of new data on the network. I wish to avoid this thread performing a polling loop, but rather to process only as needed. The scenario is as follows: A client application needs to communicate to a server via a protocol that is...

QT cross-platform issue: compiles fine on windows, linker error on linux

I have some QT code called "GUI". Via Qt Creator, I am able to compile (using gcc) it without any complaints on Windows. However, when I try to compile it (again using gcc via Qt Creator) on Linux, I get a linker error "collect2: ld returned 1 exit status". The only non-QT library that I use is the STL's vector library. (To make matt...

C++ Cross Platform Dynamic Libraries; Linux and Windows

Hey guys I needed some help on writing cross-platform code but not an application but a library. I am creating a library both static and dynamic with most of the development done in Linux, I have got the static and shared library generated in Linux but now wanted to generate a windows version of a static and dynamic library in the form ...

why does pointer to array fails to return as **

I don't understand why the following fails: #include<string> class Foo { public: std::string** GetStr(){return str;} private: std::string * str[10]; }; Thanks ...

C++ multiple processes?

I've got a project that consists of two processes and I need to pass some data between them in a fast and efficent manner. I'm aware that I could use sockets to do this using TCP, even though both processes will always exist on the same computer, however this does not seem to be a very efficient solution. I see lots of information abou...

Fastest base conversion method?

Right now I'm working on a project which requires an integer to be converted to a base 62 string many times a second. The faster this conversion is completed, the better. The problem is that I'm having a hard time getting my own base conversion methods to be fast and reliable. If I use strings, it's generally reliable and works well, bu...