c++

how to do? User type some numbers and then another function return result of addition of these numbers? (C/C++)

how to do? User type some numbers and then another function return result of addition of these numbers? (C/C++) for example, user type in 3 4 7 and then he see printed on screen 14 another one, user type 5 6 and gets 11 I'm a beginner in programming C, so I ask you to help me, please ...

Overload += operator if + is overloaded?

Possible Duplicate: Overloading += in c++ Do I need to overload the += operator if I overload + or will the compiler know what to do? Thanks. ...

Creating a container 'thing' in C++ to hold static functions. What should 'thing' be?

Hi there. I'm currently building a set of common functions (Search algorithm implementations), and think I'm doing the grouping wrong. At the moment, I have a class, Sorting, that is declared in a file called Sorting.h (it's nowhere near finished yet, btw) like so: #ifndef SORTING_H #define SORTING_H #include <vector> class Sorting { ...

what is a ofstream desination?

In the following C++ function: void save_data(ofstream &csv){ csv << "a message"; } something I cannot understand: if save_data is called, where does it write to? a file? How is it used exactlly? thanks! ...

Address of Stack and Heap in C++

Correction: I messed up with the concept of pointer address and the address the pointer points to, so the following code has been modified. And now it prints out what I want, variable a, c, i, j, k, p are on the stack, and variable b,d are on the heap. Static and global variables are on another segment. Thanks a lot for all of you! ...

C++ - calling derived function from abstract base pointer

Hello, I have been trying to create a TCP Server model based on inheritance, with varying success. These servers are managed by a singleton whose task it is to shut these servers down and other simple maintenance functions: class TCPServer { public: TCPServer(); ~TCPServer(); void Bind(TCPDaemon *daemon) { if(!daemo...

C++ templates declare in .h, define in .hpp

I saw some code in which the developer defined a class template in a .h file, and defined its methods in a .hpp file. This caught me a bit by surprise. Are there are particular conventions in C++ when dealing with templates and what files they should be in? For example say I had a Vector class template with methods for vector operatio...

dynamic 2D arrays in C / Objc

Hey guys I was wondering how I should do dynamic arrays in objc. Currently I have a function I wrote called malloc2D that looks like this: void* malloc2D(size_t unitSize, uint firstCount, uint secondCount){ void** pointer = malloc(sizeof(id) * firstCount); for (int i =0; i < firstCount; i ++){ pointer[i] = malloc(unitSize * second...

Defining routines for use with volatile and non-volatile objects

I find myself wanting to write a routine that will operate on both volatile and non-volatile memory blocks. Something along the lines of: void byte_swap (unsigned * block_start, size_t amount) { for (unsigned * lp = block_start; lp < block_start + amount; lp++) { *lp = htonl(*lp); } memcpy (block_start, some_other_ad...

How can an app hook into text selection system-wide?

I'd like to be able to track text selections across any application -- is there a hook to enable this behavior on Win32? Bonus: Anyone gurus know the equivalent hooks for OS X & Linux? ...

Can't compile C++ in Ubuntu using GCC -- Include/Library Problems (collect2: ld returned 1 exit status)

I guess I'm not linking something right? I want to call ABC.cpp which needs XYZ.h and XYZ.cpp. All are in my current directory and I've tried #include <XYZ.h> as well as#include "XYZ.h". Running $ g++ -I. -l. ABC.cpp at the Ubuntu 10 Terminal gives me: `/tmp/ccCneYzI.o: In function `ABC(double, double, unsigned long)': ABC.cpp:(.text...

Get the list of methods of a class

Is there a way to create a list (e.g. an array) of pointers to each method of a C++ class? Something like Type.GetMethods() in the .NET framework, but using only standard C++. ...

Current function address - x64

Hello, I am working on this small project where I'd like to generate the call graph of an application - I am not planning to do anything complex, it is mainly for fun/experience. I am working on x64 platform. The first goal I set myself is to be able to measure the time spent in each function of my test application. So far my strategy ...

How to document functions in described technique of creating C++ .Net dll's?

So here we have a technique, and here some more on it, of creating C++ DLLs with functions readable by .Net languages such as C#. The main Idea of technique as I use it (I can be ideologically wrong but it totally works for me) - you created a C++ project, it worked, now you want to use some of its functions from C# (for example you kee...

Struggling to get '==' operator overloading to work (C++).

Okay, not sure what I'm doing here, other than it's not right. Trying to overload the '==' method of a class, and it's just... not working. At least, I get a false back from my main, and the cout in the implementation of '==' doesnt output. These are my three files: // TestClass.h #ifndef TESTCLASS_H #define TESTCLASS_H class TestCla...

What to consider with regards to alignment when designing a memory pool?

I'm working on a memory pool for a small game engine. The main use will be as a segregated storage; a pool contains object of a specific type and size. Currently the pools can be used to store anything, but allocations will be done in blocks of a specific size. Most of the memory need will be allocated at once, but "overgrowth" can be e...

How do I receive raw, layer 2 packets in C/C++?

How do I receive layer 2 packets in POSIXy C++? The packets only have src and dst MAC address, type/length, and custom formatted data. They're not TCP or UDP or IP or IGMP or ARP or whatever - they're a home-brewed format given unto me by the Hardware guys. My socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW) never returns from its recvfrom(). ...

Setting program to be autorun through registry

Hi! I have the following code: http://privatepaste.com/8364a2a7b8/12345 But it only writes "c" (supposedly, conversion to LPBYTE leaves one byte only). What's the proper way to handle GetModuleFileName and registry edit? ...

Are there advantages to a crashing on a secondary thread versus the main one?

I came across this code in a large codebase DWORD WINAPI ThreadFunc (LPVOID lpParam) { int *x = 0; *x = 1234; // Access violation return 0; } void Manager::Crash () { Log("Received a remote command to crash Server."); DWORD dwThreadId, dwThrdParam = 1; HANDLE hThread = ::CreateThread(NULL, 0, ThreadFunc, &d...

c++ left mouse button down help

ok i know how to do the left mouse button down evet(WM_LBUTTONDOWN). but im having some troubles with it. when use it with vectors it seems to add 101 elemnts everytime the left mouse button is down. i think that every time the mouse button is down, it sends 101 messages to WM_LBUTTONDOWN that causes 101 elements to be added. here is the...