c++

What does the C++ compiler error "looks like a function definition, but there is no parameter list;" mean?

#include <iostream> #include <fstream> using namespace std; int main { int num1, num2; ifstream infile; ostream outfile; infile.open("input.dat"); outfile.open("output.dat"); infile >> num 1 >> num 2; outfile << "Sum = " << num1 + num2 << endl; infile.close() outfile.close() return 0; } Thi...

What is name lookup mechanism ?

Hi! I'd like to know what C++ name lookup mechanism is. Thank you for your help :) ...

Strange constructor

Well, I'm gonna be pretty straightforward here, I just have a piece of code in c++ which I'm not sure I really understand and need some help with. Ok, to simplify lets just say I have a class that is defined like this: (the real class is a little bit more complicated, but this is what matters) class myClass : public Runnable { Sema...

Inter process communication C# <--> C++ for game debugging engine.

I am working on a debugger project for a game's scripting engine. I'm hoping to write the debugger's GUI in C#. The actual debugging engine, however, is embedded in the game itself and is written in a mixture of C, C++, and assembly patches. What's the best way to handle communication between the debugger GUI and the debugging engine? T...

C++ extern keyword on functions. Why no just include the header file?

If I understand it correctly this means extern void foo(); that the function foo is declared in another translation unit. 1) Why not just #include the header in which this function is declared? 2) How does the linker know where to look for function at linking time? edit: Maybe I should clarify that the above declaration is then fol...

C++ constant reference lifetime

hello I have code that looks like this: class T {}; class container { const T &first, T &second; container(const T&first, const T & second); }; class adapter : T {}; container(adapter(), adapter()); I thought lifetime of constant reference would be lifetime of container. However, it appears otherwise, adapter object is destroyed...

From where starts the process' memory space and where does it end?

Hi, On Windows platform, I'm trying to dump memory from my application where the variables lie. Here's the function: void MyDump(const void *m, unsigned int n) { const unsigned char *p = reinterpret_cast<const unsigned char *>(m); char buffer[16]; unsigned int mod = 0; for (unsigned int i = 0; i < n; +...

How can I use ToUnicode without breaking dead key support?

A similar question has already been asked, so I'm not going to waste time re-explaining it, an existing discussion can be found here: http://stackoverflow.com/questions/1964614/toascii-tounicode-in-a-keyboard-hook-destroys-dead-keys The reason I'm posting a new question however is that I seem to have come across a 'solution', but I'm no...

Mocking with Boost::Test

Hello everyone :) I'm using the Boost::Test library for unit testing, and I've in general been hacking up my own mocking solutions that look something like this: //In header for clients struct RealFindFirstFile { static HANDLE FindFirst(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData) { return FindFirstFile(lpFileName...

Add functions in gdb at runtime

I'm trying to debug some STL based C++ code in gdb. The code has something like int myfunc() { std::map<int,int> m; ... } Now in gdb, inside myfunc using "print m" gives something very ugly. What I've seen recommended is compiling something like void printmap( std::map<int,int> m ) { for( std::map<int,int>::iterator it = .....

Modifying an old Windows program not to call exit after a keypress without source access

I have an older C++ Windows program that I've been asked to get run in a kiosk style environment for a student project. From the main menu, hitting ESC will exit the program, which is undesirable. In ye olden days I would have trapped the keyboard interrupt or whatever and dug around to NOOP whatever JMP or CALL was getting referenced in...

operator+ overload returning object causing memory leaks, C++

The problem I think is with returning an object when i overload the + operator. I tried returning a reference to the object, but doing so does not fix the memory leak. I can comment out the two statements: dObj = dObj + dObj2; and cObj = cObj + cObj2; to free the program of memory leaks. Somehow, the problem is with returning an ob...

How to read values from file. tokenizer

I have a file in which each line contains two numbers. The problem is that the two number are separated by a space, but the space can be any number of blank spaces. either one, two, or more. I want to read the line and store each of the numbers in a variable, but I'm not sure how to tokenize it. i.e 1 5 3 2 5 6 3 4 83 54 23 ...

How to tell if two exe's are the same code-wise?

Is there a way to detect whether two EXE's (compiled from VS.Net 2008 for C++/MFC) do not have any code-level changes between them i.e. for purposes of knowing that there have been no statement changes. This is for compliance purposes when my vendor ships me an exe, ostensibly with no changes made to the code since the last time we ...

c++ process always on foreground in window OS

I have a c++ process, I want that process should always remain on foreground, kindly guide me how can I make it possible? ...

How is destroying local variables when a block is exited normally called in C++?

C++ automagically calls destructors of all local variables in the block in reverse order regardless of whether the block is exited normally (control falls through) or an exception is thrown. Looks like the term stack unwinding only applies to the latter. How is the former process (the normal exit of the block) called concerning destroyi...

C++ How to get a filename (and path) of the executing .so module in Unix

C++ How to get a filename (and path) of the executing .so module in Unix? Something similar to GetModuleFileName on Windows. ...

C++ where to initialize static const

Hi, I have a class class foo { public: foo(); foo( int ); private: static const string s; }; Where is the best place to initialize the string s in the source file? ...

What's the correct way to do a 'catch all' error check on an fstream output operation?

What's the correct way to check for a general error when sending data to an fstream? UPDATE: My main concern regards some things I've been hearing about a delay between output and any data being physically written to the hard disk. My assumption was that the command "save_file_obj << save_str" would only send data to some kind of buffer...

Declaration and initialization of local variables - what is most C++ like?

Hi, I did not find any suitable questions answered yet, so I'd like to know what is "better" C++ style in the mean of performance and/or memory. Both codes are inside a method. The question is: When to declare long prio? And what are the implications? Code 1 while (!myfile.eof()) { getline(myfile, line); long prio = strtol(line...