c++

Debugging C++ from core files with GDB

GDB seems to always just work for C programs, but for C++ I often get these cryptic stacks: (gdb) bt #0 0x08055fa4 in std::runtime_error::what () #1 0x080576c8 in std::runtime_error::what () #2 0x08057dda in std::runtime_error::what () #3 0x080580d2 in std::runtime_error::what () #4 0x08058662 in std::runtime_error::what () #5 0x0...

How do I tell if the c function atoi failed or if it was a string of zeros?

When using the function atoi (or strtol or similar functions for that matter), how can you tell if the integer conversion failed or if the c-string that was being converted was a 0 (zero)? For what I'm doing zero is an acceptable value and the c-string being converted may contain any number of zeros. It may also have leading whitespace. ...

Passing std::vector for any type to a function

Given: template<typename T> class A { B b; std::vector<T> vec1; std::vector<T> vec2; } I'd like B to have a member function that fill() that takes a reference to those to vectors and fills vec2 with values of T depending on some information contained in b. One way of doing this is overloading fill() for each possible argument ...

Yacc Grammar Debuggers: Are there any? Are they any good/help?

I've been helping augment a twenty-some year old proprietary language within my company. It is a large, Turing-complete language. Translating it to another grammar regime (such as Antlr) is not an option (I don't get to decide this). For the most part, extending the grammar has gone smoothly. But every once in awhile I'll get a reduce-r...

Generating getters & setters in XCode

I am currently using xcode for some c++ development & I need to generate getters & setters. The only way I know is generating getters & setters in Objective C style something like this - (string)name; - (void)setName:(string)value; I dont want this; I want c++ style generation with implementation & declaration for use in the header fi...

Does (!(i % j)) mean not modulus of i and j = 0?

int main() { int i,j; for (i=1; i<=25; i++) { for (j=2; j<= i/2; j++) if (!(i%j)) break; if (j>i/2) cout << i << "\n"; } return 0; } This program (not written by me) outputs the prime numbers from 1 to 25, including 1 even though 1 isnt prime. I am having trouble with this line: if (!(i%j)) break; Does this say "not modu...

To restrict size of components at design time: CodeGear C++ Builder

Hi, I am trying to inherit from TButton in order to provide some size aware capabilities, where the buttons are able to resize themselves and/or their font size (within certain constraints) to allow for changes in text e.g. | small | or |   this is a really long   | | sentence on a button | could happily be th...

How to read a value with operator>> but no default constructor to the value ?

template <class T> T Read () { T t; cin >> t; if (cin.fail()) { // ... } return t; } This generic code read value of type T with some additional error handling. It relies on having operator>> that can parse T, and in this way it is extensible to new types. What I didn't realize is that it relies on T having a default co...

Why to use __declspec(dllexport)? Seems to be working without it.

Been a while since I have programmed in C++, so the whole export/import idea slipped off my mind. Can you explain me why to use __declspec(dllexport) & import thingy if it looks like I can use classes from other libraries without those. I have created a solution in VC++ 2005, added the console applicaiton project and two dll libraries...

How can I catch a ctrl-c event? (C++)

How do I catch a ctrl-c event in C++? ...

Using Qt with DirectX?

What exactly are my options? I have programs I need to write in OpenGL and DirectX, and I'd like to use Qt for OpenGL, and not have to re-implement half my program for the DirectX components of my task. I've looked on Google and I have found references to people complaining about Direct3D being a dependency of Qt, and people talking abo...

Can C++ compiler try different (template T) implementations until it finds one that compiles (for T)?

// First try this: template <class T> T Read(istream& in) { T t; in >> t; return t; } // If there is no operator>>(istream&, T) try this: template <class T> T Read(istream& in) { return T (in); } // If there is no constructor T(istream&) try this: template <class T> T Read(istream& in) { return T::OfStream (in); } // now...

iPhone App: Making a webpage accessible only to people using a specific app.

Hi all! I was just wondering if it is possible and if so what the best way to create a web-page that is only accessible from a custom iPhone application? For example, if you tried to access the webpage from the iPhone's built in browser, or any other browser it would display an error page but when accessed from a custom built applicatio...

How does Windows identify non-Unicode applications?

I am building an MFC C++ application with "Use Unicode Character Set" selected in Visual Studio. I have UNICODE defined, my CStrings are 16-bit, I handle filenames with Japanese characters in them, etc. But, when I put Unicode strings containing Japanese characters in a CComboBox (using AddString), they show up as ?????. I'm running Wi...

Why does a derivative trading position always require C++ knowledge?

I’ve never worked in a trading environment before and I was curious to see that few of the trading houses seem to use C#, but most of them do heavily rely on C++. Why is it? Is it because C++ is better performance wise? Is it because of legacy code bases? Is it because of cross-platform issues? What about dynamic languages (Ruby, P...

Qt - Find mouse screen x,y - even application closed.

Hello, I'm new to Qt. I'd like a window to follow the mouse around the screen. (It's a useful aid to reading) The best I can come up with is a timer that uses QPoint QCursor::pos() to move the window every .1 seconds. Rather than spinning this timer constantly, is there an event system I can tap into? This would look smoother, and u...

How do you do inheritance in a non-OO language?

I read that early C++ "compilers" actually translated the C++ code to C and used a C compiler on the backend, and that made me wonder. I've got enough technical knowledge to wrap my head around most of how that would work, but I can't figure out how to do class inheritance without having language support for it. Specifically, how do yo...

Why is complex<double> * int not defined in C++?

The C++ program #include <complex> #include <iostream> int main() { std::complex<double> z(0,2); int n = 3; std::cout << z * n << std::endl; } yields an error: no match for ‘operator*’ in ‘z * n’. Why? I'm compiling with g++ 4.4.1. Perhaps the compiler is just following the C++ standard, in which case my question is: why does...

DllImport method isn't receiving data

BYTE* pImageBuffer = NULL; eResult res = PlayerLib::CreateImageSnapshot( iPlayerRef, eBMP, &pImageBuffer ); if( res > 0 ) { .... // do something with the image WriteFile(FileHandle, pBuffer, eRes, NULL, NULL); ReleaseImageSnapshot( pImageBuffer ); // free the ...

Resources in a static lib file - MFC

MFC is failing to launch my dialog boxes, it seems, because it can't find the resource identifiers. The dialog boxes are in a separate .lib file (so it has a separate .rc file, which, I'm assuming, somehow conflicts with the one in my .exe file). How should I be handling this situation? ...