c++

Help a C++ newbie understand his mistakes: header files and cpp files

So I finished my first C++ programming assignment and received my grade. But according to the grading, I lost marks for "including cpp files instead of compiling and linking them". I'm not too clear on what that means. Taking a look back at my code, I chose not to create header files for my classes, but did everything in the cpp files (...

How do I use _W64 and __w64 in VC++?

There's such thing as __w64 in Visual C++ 9. I came across it while trying to port my native C++ DLL to 64 bit. In particular in crtdefs.h there's this nice snippet: #if !defined(_W64) #if !defined(__midl) && (defined(_X86_) || defined (_M_IX86)) && _MSC_VER >= 1300 #define _W64 __w64 #else #define _W64 #endif #endif which if I get it...

What is #defined if a compiler is Cpp0x compliant?

Is there any official, or inofficial, #defines for when a compiler is Cpp0x compliant? Even better, for specific Cpp0x functionality (~#cpp0xlambda, #cpp0xrvalue etc)? (Haven't found anything about this on the net) ...

Overloading operator>> to a char buffer in C++ - can I tell the stream length?

I'm on a custom C++ crash course. I've known the basics for many years, but I'm currently trying to refresh my memory and learn more. To that end, as my second task (after writing a stack class based on linked lists), I'm writing my own string class. It's gone pretty smoothly until now; I want to overload operator>> that I can do stuff ...

Python-equivalent of short-form "if" in C++

Is there a way to write this C/C++ code in Python? a = (b == true ? "123" : "456" ) Thanks so much! ...

Downside of this macro construct and possible alternatives

I recently saw some code using macros like #define CONTAINS(Class, Name)\ private:\ std::list<Class> m_##Name##s;\ public:\ void add_##Name(const Class& a_##Name) {\ m_##Name##s.push_back(a_##Name);\ }\ int get_##Name(int pos) {\ return m_##Name##s.at(pos);\ }\ ...

Write directly to screen with c++

Hello I am new to c++ and am wondering where to go about looking to print directly to the screen? For example the HUD interface that appears on laptops when you change the volume. I'm not really looking for any fancy graphics, just, say, a variable or info from a file. I've tried googling but havn't come up with anything yet. So...whe...

What is a very practical C++ book?

While I agree reading books is always a learning experience, sometimes you'd like to skip the theory and just jump till you reach the practical aspects. For example, I'd like to see a book that tells me that by writing: char* a = "a string"; the value of a will (usually) get stored in the readonly portion of an executable, and explain...

C++ map really slow?

i've created a dll for gamemaker. dll's arrays where really slow so after asking around a bit i learnt i could use maps in c++ and make a dll. anyway, ill represent what i need to store in a 3d array: information[id][number][number] the id corresponds to an objects id. the first number field ranges from 0 - 3 and each number represents...

stl vector and c++: how to .resize without a default constructor?

how could I tell STL, specifically for the method resize() in vector, to initialize objects with a constructor other than default, and with which parameters? I mean: class something { int a; something (int value); } std::vector<something> many_things; many_things.resize (20); more generally, how could I force STL to use my ...

Is it possible to get the output of a program while it's running?

If I have a windows console program written with c++, is it possible to retrieve that program's standard output, while the program is running? And if not, what would be the best way to rewrite the program? I know I could output to files and continuously check those files for updates. Is there another way? Is there a better way? ...

Adding publicly but inheriting private

I want to add a class directly into a new class by avoiding public inheritance. For example I have a class like class size { private: int width; int height; public: void set_width(int w) { width = w; } int get_width() { return width; } void set_height(int h) { height = h; } int get_height() { return height; } ...

C++ positional parameters

Hi. This is a very basic question, so please bear with me. Consider the following function in C++: void foo(int a, int b, int c) { //do something } can I call this funtion like this: foo(b=2, c=3, a=2) ? I suppose this have some sort of name (positional parameters, possibly). If you could clarify it in the answer too, it would g...

Simple telnet example in LIBCURL - C++

I need to fing simple TELNET example in LIBCURL (curl.haxx.se/libcurl) (C++) I searched over this site, but I don't found any simple example. I need only to connect to TELNET, authenticate, and send message. Thanks ...

Can you explain the following C/C++ statement?

void (*func)(int(*[ ])()); ...

How to call C++ functions/methods via JavaScript

Hi, does anybody know how to call C++ functions or methods via JavaScript. Need scripting like Lua/Python-C++ but with JavaScript. Thanks in advance. ...

Calling unmanaged function from C#: should I pass StringBuilder or use unsafe code?

I've got a C# program that needs to pass a char buffer to an unmanaged function. I've found two ways that seem to work reliably, but I'm not sure which I should choose. Here's the unmanaged function's signature. extern "C" __declspec(dllexport) int getNextResponse(char *buffer); The first option is to define the buffer as a StringBui...

boost serialization access to protected data

Hi, When I try to serialize class with protected members, I get the following errors: "cannot access protected member declared in class NetElement". The idea is that I'd like to have one serialization function outside of class definition. What am I doing wrong? best regards, mightydodol Here is the code... // class definition clas...

How can I set the size of an Ace activation Queue?

That is, how can i limit the number of tokens/elements the Queue can hold? Example: I have a low level driver that can only process one request at a time. I am using the Ace activation Queue to limit the request (there could be up to 10 pending), but only one is allowed to go on the bus. The rest have to wait until the first request ...

Why is type_info declared outside namespace std?

Hi, I'm using VS2005 and the MS implementation of STL. However, the class type_info in is declared outside of "namespace std". This creates some problems for third party libs that excepts to find a std::type_info. Why is this so, and is there any workaround? Here is a sample from the beginning of typeinfo: class type_info { ... }; _S...