c++

what will be behavior of following code snippet ?

What will be the behavior and output of the following code if i accidentally code so in C/C++, float a = 12.5; printf("%d\n", a); printf("%d\n", *(int *)&a); ...

Help with Boost Graph Library and C++

I am trying to use the boost graph library in C++* I want to create a topological sort for my graph. However the output I want on my graph is the actual names of the vertex, not the number positions. For example on the following example I get the following output: A topological ordering: 45 40 41 34 35 33 43 30 31 36 32 26 27 25 23 24 1...

Why does stack overflow throw no error in Visual C++?

In Microsoft Visual C++ 2010 I created a program which delibrately causes a stack overflow. When I run the program using "start debugging" an error is thrown when stack overflow occurs. When I run it with "start without debugging" no error is thrown and the program just terminates silently as if it had successfully completed. Could someo...

C# / C++ Interop Error on Function Call

I'm working on an internal project based on the Registration Free Com-Server in Microsoft's All-In-One Microsoft's All-In-One Framework. The sample shows how to generate a registration free c# COM server for a c++/native code application. As a newbie at doing COM-Interop, using this demo seemed like a good idea. This sample shows how ...

Inclusion problem

I have an inclusion pattern as follows: /* * Class1.h */ #ifndef CLASS1_H_ #define CLASS1_H_ #include "Class2.h" namespace Class1_namespace { class Class1 { Class2* Class2_ptr; void Class1_member() { (*Class2_ptr).Class2_method(); } }; } #endif /* CLASS1_H_ */ /* * Class2.h */ #ifndef CLASS2_H_ #define CLASS2_H...

C++ location of main

If I put main on the top of the source file and invoke some custom functions, it will tell me that those functions are not found, but if I put main on the bottom of the source file, it will work. Why? Is it because the compiler parse from top to bottom and breaks at the definiteion of main? ...

Linking Errors While creating a shared library

Hello, I currently have some C++ code that I want to compile into a shared library that I can dynamically link to a Java application during runtime using the Java Native Interface (JNI). The problem that I'm facing is - the C++ code that I'm trying to compile calls on another library itself, making use of a lot of classes and different h...

How to activate a window of an external application

I've used FindWindow to get a handle to a window of an external application. How can I use this handle to activate the window of the external application, if it is minimized or behind other applications on the windows desktop? ...

Mutually recursive classes

How do I implement mutually recursive classes in C++? Something like: /* * Recursion.h * */ #ifndef RECURSION_H_ #define RECURSION_H_ class Class1 { Class2* Class2_ptr; public: void Class1_method() { //... (*Class2_ptr).Class2_method(); //... } }; class Class2 { Class1* Class1_ptr; public: void C...

Why does the following program give a error?

Why does the following program give a warning? Note: Its obvious that sending a normal pointer to a function requiring const pointer does not give any warning. #include <stdio.h> void sam(const char **p) { } int main(int argc, char **argv) { sam(argv); return 0; } I get the following error, In function `int main(int, char **...

C++: Inheritance and Operator Overloading

I have two structs: template <typename T> struct Odp { T m_t; T operator=(const T rhs) { return m_t = rhs; } }; struct Ftw : public Odp<int> { bool operator==(const Ftw& rhs) { return m_t == rhs.m_t; } }; I would like the following to compile: int main() { Odp<int> odp; odp = 2; ...

Why is it dangerous to get rid of volatile?

Hello guys, In C++, volatile is treated the same way const is: passing a pointer to volatile data to a function that doesn't want the volatile modifier triggers a compile error. int foo(int* bar) { /* snip */ } int main() { volatile int* baz; foo(baz); // error: invalid conversion from ‘volatile int*’ to ‘int*’ } Why is it d...

C++: Using base class's private members in equality test

I would like the following to compile, but it does not: template <typename T> struct Odp { public: operator*() const { return m_p; } T* operator->() const { return m_p; } T** operator&() { return &m_p; } private: T* m_p; }; struct Ftw : public Odp<int> { bool o...

Need some help with C++ Trie data structures

Hi, I am trying to write a C++ function that matches whether a string is present in a dictionary . It can be a partial string or a complete string. SO I read each and every line into a trie trie< std::string, int > dict; dict.insert(make_pair(line,i++)); // when i search for a string it always returns ...

Is there any website which offers C++ IDE to run the codes in the cloud?

Is there any website which offers C++ IDE to run the codes in the cloud? Something like this which is for Python and matlab (octave in fact); ...

Sending Keyboard Commands

How would I send a keyboard command, so that they press "Y", then hit enter. Thanks ...

LD_PRELOAD for C++ class methods

I need to interpose on a method call in a C++ program (the class resides in a separate shared library). I thought I could use LD_PRELOAD, but i am not sure how this would work (i only found examples of C functions): is there a way to setup interposition for a single method without copying over any code from the interposed class implement...

system call to copy files

how to create a system call on c++ that copies one file to the other files? ...

How do you create file with a variable in C++?

I was wondering how to put a variable where the bold text is text is: ofstream file; file.open ("example.txt"); ...

Incremental Decision Tree C++ Implementation

Do anyone know any incremental implementation of decision tree classifier. Such that it could generate optimal decision tree classifier when you add new instance to training set with low computation and as quick as possible according existing decision tree classifier? In other words I have an optimal decision tree classifier of set A, w...