In C++, RAII is often advocated as a superior approach to exception handling: if an exception is thrown, the stack is unwound, all the destructors are called and resources are cleaned up.
However, this presents a problem with error reporting. Say a very generic function fails, the stack is unwound to the top level and all I see in the l...
I've got a background thread that is polling a server.
When there's data, i want to handle the data on the ui thread.
If I store the hwnd of the main window.
How can I get a particular method --
static void DataHandler(void* data)
to be executed on the ui thread.
I think creating a timer passing the hwnd and the function pointer w...
I seem to be having a bit of a TEXT / UNICODE problem when using the windows CreateFile function for addressing a serial port. Can someone please help point out my error?
I'm writing a Win32 console application in VC++ using VS 2008.
I can create a handle to address the serial port like this:
#include <iostream>
#include <windows...
I have a .NET_4 Managed C++ ref class that I derive from a .NET_4 base class written in C#.
EXAMPLE::
{
C# BASE CLASS::
namespace Core
{
public class ResourceManager
{
public class _Resource
{
public virtual void Delete() {}
}
}
}
}
MANAGED C++ CLASS
namspace Input.DI
{
public ref class Mouse : ResourceManager...
We commonly use random() function to create random numbers in C++.
The use of void srand (unsigned int seed) would improve the results since it would generate random numbers depending on the value of seed.
Can anyone tell me how the random function is actually implemented?
...
// todo: create the connection here
// Construct the query string. You were already doing this in your code
std::ostringstream query_builder;
query_builder << "select pipe_id from pipe where version_id='" << id << "'";
// Convert the ostringstream to a string
std::string query_string = query_builder.str();
// Construct a query object...
I am using CodeSourcery's implementation of the vector signal image processing library (vsipl++). I have written a function that is supposed to return [I + a*A]^-1 B, where I is the identity matrix, and A and B are compatible square matrices, as follows:
namespace vsipl {
template< class T1, class T2, class O1, class O2, class L1, cla...
hi,
How to pass optional parameters to a method in C++ ?
Any code snippet...
...
Hi, I have a school problem but I do not understand what it actually asks. Any of you have an idea what it's really asking for? I don't need code, I just need to understand it.
This is the problem:
Construct a computer program that uses the Secant method to solve the problem:
f(x) = (1+x) cos( sin(x)3 ) - 1.4 = 0
Starting with th...
Let's say I have the following class:
class Foo
{
public:
Foo()
{
Bar();
}
private:
Bar(bool aSendPacket = true)
{
if (aSendPacket)
{
// Send packet...
}
}
};
I am writing a test harness which needs to create a Foo object via the factory pattern (i.e. I am not instan...
I have this simple problem that gets an input from the user using a function then checks if the input is 'equal' to the "password". However, strcmp would never return my desired value, and the culprit is somewhere in my loop that uses getch() to take each character separately and add them to the character array. I found this out by havin...
I'm preparing for a job interview. I was stuck at one of the binary tree questions:
How can we calculate the sum of the values present in all the nodes of a binary tree?
Thanks in advance.
...
I am Creating the Registry Key using following code:
LPCTSTR lpNDS= TEXT("SOFTWARE\\myKEY");
if(OK==ERROR_SUCCESS)
{
MessageBox ( NULL, "Success",
_T("SimpleShlExt"),
MB_ICONINFORMATION );
}
else
{
MessageBox ( NULL, "Failed" ,
...
So I wanna make a PDF reader using C++ as a hobby project. The problem is I am not finding much of head start so if anyone has worked on similar project please guide me, a few web links would be great! I will be using windows environment and Visual studio.
...
I don't understand why in the following code, I am allowed to create the function print_private_template while the compiler complains about print_private_class:
#include <cstdio>
class A
{
private:
template <unsigned T>
struct B
{
};
struct C
{
};
public:
templ...
Hello,
auto a = (Foo<T>*)malloc(sizeof(Foo<T>));
auto *b = (Foo<T>*)malloc(sizeof(Foo<T>));
I don't think it's important that templates are there, but the question is: are a and b of the same type?
g++ -std=c++0x -Wall (4.4) doesn't give any errors or warnings, but I haven't run the program so I don't know if it does the same thing.
...
Hey all, having a bit of a problem with a recent project. The goal here is to be able to input several lines of text containing a date in mm/dd/yyyy format followed by a whitespace and then a description of the event. I've accomplished actually allowing for multiple lines of text input (I think), but now I'm not exactly sure how to stop ...
Ok, it's been a while since I wrote in C++.
and I've never done anything quiet this high level.
So basically I need to create a class.
The constructor for the class needs to take a reference (or pointer) to a method form another class, or to a function.
Basically I have a class that needs to on occasion read a value from a fltk valuato...
In C bitwise left shift operation invokes Undefined Behaviour when the left side operand has negative value.
Relevant quote from ISO C99 (6.5.7/4)
The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1× 2E2, reduced modulo
on...
Recently I have learnt of the many benefits (including beautiful looking code) of OOP.
So, now I am trying to write a small physics API for my personal use, perhaps to be put in a few little games. This is mainly because I like to practice coding, and I like my physics.
But the thing is, many APIs have an interface like this (including...