c++

Creating Binary Block from struct

I hope the title is describing the problem, i'll change it if anyone has a better idea. I'm storing information in a struct like this: struct AnyStruct { AnyStruct() : testInt(20), testDouble(100.01), testBool1(true), testBool2(false), testBool3(true), testChar('x') {} int testIn...

Converting a macro to an inline function

I am using some Qt code that adds a VERIFY macro that looks something like this: #define VERIFY(cond) \ { \ bool ok = cond; \ Q_ASSERT(ok); \ } The code can then use it whilst being certain the condition is actually evaluated, e.g.: Q_ASSERT(callSomeFunction()); // callSomeFunction not evaluated in release builds! VERIFY(call...

How do I assign an alias to a function name in C++?

It's easy to create a new name for a type, a variable or a namespace. But how do I assign a new name to a function? For example, I want to use the name holler for printf. #define is obvious... any other way? Solutions: #define holler printf void (*p)() = fn; //function pointer void (&r)() = fn; //function reference inline void g(){ f(...

Optimal setup for Doxygen in a large multi-application COM project

A system has up to 100 VC++ projects, each spitting out a DLL or EXE. In addition there are many COM components with IDL and generated .h/.c files. What's 'the right way' or at least a good way to organise this with Doxygen? One overall doxy project or one per project/solution? And what's the right way to handle COM, which has generated...

How to declare ULARGE_INTEGER in c#?

Based upon this question How to declarate LARGE_INTEGER in C# with answer of: [StructLayout(LayoutKind.Absolute, Size=8)] struct LARGE_INTEGER { [FieldOffset(0)]public Int64 QuadPart; [FieldOffset(0)]public UInt32 LowPart; [FieldOffset(4)]public Int32 HighPart; } Is my assumption below for declaring ULARGE_INTEGER correct?...

Qt - How to place a QTextEdit with left and right margins in a QVBoxLayout?

How to place a QTextEdit with left and right margins in a QVBoxLayout? I could use, of course, a QHBoxLayout, place the QTextEdit into that horizontal layout in between to spacings (addSpacing(40)) and only then the horizontal layout could add into the vertical layout, but want to know if there is a direct way of doing that. ...

Declaration of struct variables in other class when obtained by getters

Hi, I am using Qt 4.5 so do C++. I have a class like this class CClass1 { private: struct stModelDetails { QString name; QString code; ..... // only variables and no functions over here }; QList<st...

error C2504: 'BASECLASS' : base class undefined

I checked out a post similar to this but the linkage was different the issue was never resolved. The problem with mine is that for some reason the linker is expecting there to be a definition for the base class, but the base class is just a interface. Below is the error in it's entirety c:\users\numerical25\desktop\intro todirectx\godfi...

Difference between Object var() and Object* var = new Object()

If I have an Object class named, what's the difference between create an instance just like that: Object var; and: Object* var = new Object(); ? ...

Is a C++ compiler allowed to emit different machine code compiling the same program?

Consider a situation. We have some specific C++ compiler, a specific set of compiler settings and a specific C++ program. We compile that specific programs with that compiler and those settings two times, doing a "clean compile" each time. Should the machine code emitted be the same (I don't mean timestamps and other bells and whistles...

How do I implement a dictionary "with a Python tuple" as key in C++?

I currently have some python code I'd like to port to C++ as it's currently slower than I'd like it to be. Problem is that I'm using a dictionary in it where the key is a tuple consisting of an object and a string (e.g. (obj, "word")). How on earth do I write something similar in C++? Maybe my algorithm is horrendous and there is some wa...

C - Convert time_t to string with format YYYY-MM-DD HH:MM:SS

Hello, is there any way to convert a time_t to a string with the format YYYY-MM-DD HH:MM:SS automatically, keeping the code portable? ...

Why doesn't C++ allow you to request a pointer to the most derived class?

(This question should probably be answered with a reference to Stroustrup.) It seems extremely useful to be able to request a pointer to the most derived class, as in the following: class Base { ... }; class DerivedA { ... }; class DerivedB { ... }; class Processor { public: void Do(Base* b) {...} void Do(DerivedA* d) {...} voi...

How to create named pipe acsessible Only on your machin? (VS08 C++)

Hello, I have created a program that write video stream to a named pipe on windows, using Visual Studio C++ 2008 . how to be sequre that no one exept programms on this computer can acsess this pipe? npipe = CreateNamedPipe("\\\\.\\pipe\\TestChannel", PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES , 1024...

ASCII definition of symbol

I've spent hours with no luck on this. In terms of cmd prompt, what does the white filled in square with a 1 followed afterwards mean? e.g. http://i1012.photobucket.com/albums/af249/dororoj/square1.jpg I've tried using string.find() (using C++) with various hex symbols listed on the ascii table at: http://web.cs.mun.ca/~michael/c/asci...

how to avoid header coupling

I am trying to address this issues because I can not seem to find a good resource online that does so. I do not fully understand the issue cause I never got it resolved so I will try to describe it as best as possible. Awhile ago I had an issue where headers were being ignored because "They were called once already and therefore when ...

Does any compiler support constexpr yet?

I want to play with constexpr, does any compiler support it yet? ...

TCHAR* envp[]: What is it?

I created a VC++ console project with Visual Studio and it auto-generated this function: int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { ... } I was just wondering what envp stands for and how/when I can/should use it? Thank you! ...

Is there STDCALL in Linux?

hello, I'm trying to port a Windows app to Linux. This appplication marks some functions with the __stdcall attribute. However, i was told by a friend that stdcall is used only on windows and has no meaning in linux (but DOES exist in Windows GCC). I tried to search Google about that, and got some results state that there IS stdacll in L...

can somebody figure out what is wrong in this? I am getting linking error.

#include <iostream> using namespace std; extern int i; int main() { i=10; cout<<"the value of i is"<<i<<endl; } ...