c++

Source code hierarchies and header files (C++)

What’s the preferred way to reference header files from cpp files that are in different sub-directories in a project? For example, bear.cpp in the forest directory needs to include lion.h in jungle. Is there a better way than using `#include “../jungle/lion.h”? I would prefer to set an include path and simply use #include <lion>, but ...

Converting float to double

How expensive is the conversion of a float to a double? Is it as trivial as an int to long conversion? EDIT: I'm assuming a platform where where float is 4 bytes and double is 8 bytes ...

Naming convention for fields and accessors in C++

What naming convention should I follow for class members? Right now, I’m prefixing all fields with an underscore, and using the regular name for the accessor method, e.g.: int _age and int age() { return _age; } Any preferred approaches? ...

C# running faster than C++?

A friend and I have written an encryption module and we want to port it to multiple languages so that it's not platform specific encryption. Originally written in C#, I've ported it into C++ and Java. C# and Java will both encrypt at about 40 MB/s, but C++ will only encrypt at about 20 MB/s. Why is C++ running this much slower? Is it bec...

Weird behaviour of Koenig Lookup

Hi, consider the following program: namespace NS2 { class base { }; template<typename T> int size(T& t) { std::cout << "size NS2 called!" << std::endl; return sizeof(t); } }; namespace NS1 { class X : NS2::base { }; } namespace NS3 { template<typename T> i...

In C++, how can I implement this OOP concept?

I have two implemented classes: class DCCmd : public DCMessage class DCReply : public DCMessage Both are protocol messages that are sent and received both ways. Now in the protocol implementation I'd need to make a message queue, but with DCMessage being abstract it won't let me do something like this: class DCMsgQueue{ pri...

Designing a better API?

What are the best practices and patterns to be followed for designing APIs? How to achieve implementation hiding the best way (C++/Java)? Designing APIs which are generic in nature? Any reference books/links which guide with neat examples to beginners? ...

[C++] How should I organize test cases in my project?

Hi, I have a project that looks like this: xdc/ hubactions/ hubconnection.cpp hubconnection.h uiinterface/ readme uiconnection.cpp uiconnection.h ... uiactions/ readme connectaction.cpp connectaction.h quitaction.cpp quitaction.h ... utils/ parser.cpp parser.h ... N...

How to print a double with a comma

In C++ I've got a float/double variable. when I print this with for example cout the resulting string is period-delimited. cout << 3.1415 << endl $> 3.1415 Is there an easy way to force the double to be printed with a comma? cout << 3.1415 << endl $> 3,1415 ...

Leveraging hobby experience to get a job

Like many other's I began programming at an early age. I started when I was 11 and I learned C when I was 14 (now 26). While most of what I did were games just to entertain myself I did everything from low level 2D graphics, and binary I/O, to interfacing with free API's, custom file systems, audio, 3D animations, OpenGL, web sites, et...

any good method to insert a control just like excel into MFC/c++ program ?

I need a excel-like grid control in MFC, do anyone have good suggestion to implement that ?] with the control i can filter the data by clicking on the header, then it will display distinct data of current column for selection. Thanks! ...

What Are Binding Generators For?

A friend raised this on Twitter: @name_removed doesn't understand why binding generators seem to think writing pages of XML is vastly superior to writing pages of C++... Having never encountered binding generators before, I decided to look them up. Seems pretty self-explanatory, convert C++ classes to XML format. But now I need someone ...

Need help allocating space for vector within class definition using boost.

I am trying to allocate space for a boost vector type in a class definition. I am not a good c++ programmer, but shown below is my best attempt. There are no error messages, but when I try to access the vector from my main function it believes that the vector has zero elements. I know this is because I did not tell the compiler how mu...

How do you set system time using C/C++?

I have an embedded system (ARM 9263) running an RTOS, IAR tools. The system supports the standard time() function which gives me the current time. I need the reverse call, that is I need to set the time - is there a "C" standard way to do this? I've googled around, sure thought it would be obvious, but perhaps it is platform dependent? I...

How do I turn on multi-CPU/Core C++ compiles in the Visual Studio IDE (2008)?

I have a Visual Studio 2008 C++ project that has support for using multiple CPUs/cores when compiling. In the VCPROJ file I see this: <Tool Name="VCCLCompilerTool" AdditionalOptions="/MP" ... I can't find where that was turned added via the IDE and I want to set up another project that uses all of my cores during compilat...

How to read a float from binary file in C?

Everything I'm finding via google is garbage... Note that I want the answer in C, however if you supplement your answer with a C++ solution as well then you get bonus points! I just want to be able to read some floats into an array from a binary file EDIT: Yes I know about Endian-ness... and no I don't care how it was stored. ...

Infinite Loop in C++

Why the following code could/will result in infinite loop? x=0; y=0; while(x<100) { minnum=100; maxnum=100; while(y<150) { if(random[x][y]<minnum) { minnum=random[x][y]; minX=x; minY=y; y++; } else if(random[x][y]>maxnum) { maxnum=random[x][y]; maxX=y...

How do I write to shared memory in C++?

I'd like to write to shared memory and then dump the contents to a file in the win32 api. Currently I have this code: HANDLE hFile, hMapFile; LPVOID lpMapAddress; hFile = CreateFile("input.map", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); hMapFile = CreateFileMapping(hFile, N...

C++ Compile Error: invalid operands of types `const char[2]' and `int' to binary `operator<<'

When the compiler gets here: outFile1<<"The highest number is "<<maxnum<<", and it is located at coordinates "<<maxX<","<<maxY<<"."<<endl; it gives the error invalid operands of types const char[2]' and int' to binary `operator<<' ...

talking between python tcp server and a c++ client

I am having an issue trying to communicate between a python TCP server and a c++ TCP client. After the first call, which works fine, the subsequent calls cause issues. As far as WinSock is concerned, the send() function worked properly, it returns the proper length and WSAGetLastError() does not return anything of significance. Howeve...