c++

Domain Specific Language in C/C++, does this Kosher?

I was just fooling around with some Domain Specific Language designs for a new project in C/C++ when I thought up this "odd" solution: define DSL(...) MakeCommand(#__VA_ARGS__\ )->Exec()->GetResults() MyResults results = DSL( for p in people do something ); The nice part is this is correct by the stand...

Why is there "class" in "template <class x>"?

What does the "class" part of a template statement do? Example: template <class T> class Something { public: Something(const T &something); } And what else can go there? I usually only see "class". ...

c++ template instantiation

I have a template class like below. template<int S> class A { private: char string[S]; public: A() { for(int i =0; i<S; i++) { . . } } int MaxLength() { return S; } }; If i instantiate the above class with different values of S, will the compiler create different instances of A() and MaxLent...

How to know the exact line of code where where an exception has been caused (C++)?

If I generate an exception by myself, I can include any info into the exception: a number of code line and name of source file. Something like this: throw std::exception("myFile.cpp:255"); But what's with unhandled exceptions or with exceptions that was generated not by me? Thanks. ...

How do I resolve: "error C2039: '{ctor}' : is not a member of" in Visual Studio 2005?

I am extending a template class using C++ in Visual Studio 2005. It is giving me an error when I try to extend the template base class with: template <class K, class D> class RedBlackTreeOGL : public RedBlackTree<K, D>::RedBlackTree // Error 1 { public: RedBlackTreeOGL(); ~RedBlackTreeOGL(); and a second error when I try to inst...

Why won't my program run unless Visual Studio 2008 is installed?

I have written a game that uses GLUT, OpenGL and FMOD. The problem is that the binary won't run, unless Visual Studio 2008 is installed on the computer. Why is this? ...

Is a string literal in c++ created in static memory?

Is a string literal in c++ created in static memory and destroyed only when the program exits? ...

adjacency matrix in java or c++ to find connected nodes

Hi I am given a problem where I have been given N nodes in a graph that are interconnected to each other then given a matrix which lists down a node being connected to another (1 if it is, 0 if not). I am wondering how to best approach this problem. I think these are adjacency matrix? But how would I implement that ... Basically what...

Threading issue (chase your own tail)

There is ConnectionManager which waits for incoming connections. For each incoming connection it creates a Connection instance which handles the inbound and outbound traffic on this connection. Each Connection has a Watchdog which handles "bad connection" conditions and calls registered "Listerners". One "Listener" is the ConnectionManag...

WM_GETTEXT button action

Hi, I would like to tie an action to a PocketPC button (biggest button at the center - don't know how it is called). I tried to tie the action to WM_GETTEXT message, but this message is sent on every key press and don't know how to add an action just to the specific button. Does anyone know how this could be done? Thanks! ...

How do you determine the amount of Linux system RAM in C++?

I just wrote the following C++ function to programatically determine how much RAM a system has installed. It works, but it seems to me that there should be a simpler way to do this. Can someone tell me if I'm missing something? getRAM() { FILE* stream = popen( "head -n1 /proc/meminfo", "r" ); std::ostringstream output; int...

What C++ compilers are supporting lambda already?

Are there C++ compilers already supporting C++0x lambda expressions? ...

How do I print one bit?

Please tell me how do I print a bit, like printf("%d",bit); Thanks a lot ...

WinHttp Gets 404 File Not Found

I am grabbing a webpage with WinHttp and the resulting page is the site's 404 file not found page. I know that the code works as I have tested it with other websites. The page in question is a normal http protocol and .html file. What can I do? ...

How do you reconcile common C++ naming conventions with those of the libraries

Most C++ naming conventions dictate the use of camelCaseIdentifiers: names that start with an uppercase letter for classes (Person, Booking) and names that start with a lowercase letter for fields and variables (getPrice(), isValid(), largestValue). These recommendations are completely at odds with the naming conventions of the C++ libr...

Starting an application under windows using start

I noticed that I can start a program with it's associated handler by writing start filename. However, for some files, all I get is a console, and I don't know why. I'm trying to populate a list control in MFC, and I want to have the program and it's associated handler to run when I double click the selection. Is there a better way, or an...

Qt: set a default cursor for an application

In a Qt application, is there an equivalent to QApplication::setFont that sets the applications default cursor, to be overwritten by setting one on a specific widget? QApplication::setOverrideCursor overrides all widget specific ones, I want local ones to take precidene over this one, but still use my cursor if I didn't specify one. t...

Emacs and C++

Once again it is time to clean up my emacs setup. Before I go cleaning it up, are there any packages that you would recommend above and beyond c++-mode, cedet, ecb, speedbar etc. ? Especially stuff that's new in the last five years. ...

MFC Equivalent to Java File#isDirectory()

Is there an equivalent to the Java File method isDirectory() in MFC? I tried using this : static bool isDirectory(CString } but it doesn't seem to work. ...

printf("something\n") outputs "something " (additional space) (g++/linux/reading output file with gedit)

I have a simple C++ program that reads stdin using scanf and returns results to stdout using printf: #include <iostream> using namespace std; int main() { int n, x; int f=0, s=0, t=0; scanf("%d", scanf("%d", for(int index=0; index<n; index++) { scanf("%d", scanf("%d", scanf("%d", ...