One of the very tricky question asked in an interview...
we need to swap the values of two variables like a=10 and b=15
Generaly to swap two variables values, we need 3rd variable like..
temp=a
a=b
b=temp
Now the requirement is, swaping value of two variable values without using 3rd variable?
How can be accopmplish this?
...
To prevent my application changing the window content while user is moving its window around, I capture messages WM_ENTERSIZEMOVE / WM_EXITSIZEMOVE and I pause the application between the messages. However, sometimes it happens I receive WM_ENTERSIZEMOVE but no WM_EXITSIZEMOVE at all. One repro is:
open the window menu
click on Size
do...
I have two vector classes:
typedef struct D3DXVECTOR3 {
FLOAT x;
FLOAT y;
FLOAT z;
} D3DXVECTOR3, *LPD3DXVECTOR3;
and
class MyVector3{
FLOAT x;
FLOAT y;
FLOAT z;
};
and a function:
void function(D3DXVECTOR3* Vector);
How is it possible (if it's possible) to achieve something like this:
MyVector3 vTest;
f...
How can one swap pointer addresses within a function with a signature?
Let's say:
int weight, height;
void swap(int* a, int* b);
So after going out of this function the addresses of the actual parameters (weight and height) would be changed. Is it possible at all?
...
First_Layer
I have a win32 dll written in VC++6 service pack 6. Let's call this dll as FirstLayer. I do not have access to FirstLayer's source code but I need to call it from managed
code. The problem is that FirstLayer makes heavy use of std::vector and std::string and there is no way of marshaling these types into a C# application dir...
Hey all,
I have the following scenario: I have a single thread that is supposed to fill a
container with pairs of integers (in essence, task descriptions), and I have a large
number of worker threads (8-16) that should take elements from this container and perform
some work.
I thought the problem could be easily solved by a blocking q...
A little is hidden in Qt given splendid documentation.
But given vastness of Qt functionality paradoxically many useful features have been overlooked by me (and reimplemented or work-arounded).
What Qt functions you wish you have noticed earlier?
...
Can strings be used as template arguments?
I tried:
template <char *str>
struct X
{
const char *GetString() const
{
return str;
}
};
int main()
{
X<"String"> x;
cout<<x.GetString();
}
And although I get no complaints about the class definition, the instantiation yeilds 'X' : invalid expression as a templ...
i doint project about process realtime data from cyber glove( Virtual Hand ) . So i need to write some application that get realtime data from glove and feed to some algorithm. i don't know how to deal with process realtime data, anybody hav some resource?
...
Hi,
I'm creating a process and making a lot of kernel objects requisition to the system. My code is that:
int main(){
//Cria processo para o Data Viewer Unit
LPSTARTUPINFOA si;
PROCESS_INFORMATION pi;
// Start the child process.
if(!CreateProcessA(
"E:\\Documents\\Faculdade\\Matérias\\Automação em Tempo R...
Hi, I'm working on a project and it's in a stage that I don't know what's wrong. Here's the simplified version:
The code:
class Base { // This base class is pure abstract
public:
virtual ~Base(); // Necessary to trigger destructors in inherited classes
virtual baseFunc() = 0;
};
...
I have a fairly large C++ project, and am trying to use the debugger to step through some code. Unfortunately, it sometimes decides to drop out of that mode, and just execute the code without paying attention to the fact that I pressed F10, and not breaking at subsequent breakpoints. I don't know when it's going to drop out, but it see...
While evaluating Visual Studio 2010 Beta 2, I see that in the converted directory my vcproj files have become vcxproj files. There are also vcxproj.filter files alongside each project which appear to contain a description of the folder structure (\Source Files, \Header Files, etc.).
Do you think these filter files should be kept per-use...
Consider the following code.
using boost::shared_ptr;
struct B;
struct A{
~A() { std::cout << "~A" << std::endl; }
shared_ptr<B> b;
};
struct B {
~B() { std::cout << "~B" << std::endl; }
shared_ptr<A> a;
};
void main() {
shared_ptr<A> a (new A);
shared_ptr<B> b (new B);
a->b = b;
b->a = a;
}
There is ...
The following code only works when the copy constructor is available.
When I add print statements (via std::cout) and make the copy constructor available it is not used (I assume there is so compiler trick happening to remove the unnecessary copy).
But in both the output operator << and the function plop() below (where I create a t...
In my current project, I have a slightly distributed architecture, i.e., several executables collaborate with each other to get things done. To make things easier, i hope i could have a reliable 'backbone' message bus: when an executable hooks up to the msg bus, it can receive callback when new msg arrives. Similarly, it can publish new ...
I get
error C2027: use of undefined type 'Bridge'
and
error C2227: left of '->receive' must point to class/struct/union/generic type
on line *connection1->receive(newMessage,2);
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define MAXHOST 10
#define MAXPORT 5
#define MAXLAN 8
#define MAXBRIDGE 5
#define MAXLANBRIDGECO...
Consider:
if (condition1)
{
// Code block 1
}
else
{
// Code block 2
}
If I know that condition1 will be true the majority of the time, then I should code the logic as written, instead of:
if (!condition1)
{
// Code block 2
}
else
{
// Code block 1
}
since I will avoid the penalty of the jump to the second code block ...
I have the following code (this is some semi-sudo code, which may not compile):
class FooBar {
public:
void a();
void b();
boost::shared_ptr<boost::thread> m_thread;
std::string m_test;
};
void FooBar::a() {
m_test = "Foo bar"
m_thread = shared_ptr<thread>(new thread(bind(&FooBar::b, this)));
}
void FooBar::b()...
Hello,
I have a variant bstr that was pulled from MSXML DOM, so it is in UTF-16. I'm trying to figure out what default encoding occurs with this conversion:
VARIANT vtNodeValue;
pNode->get_nodeValue(&vtNodeValue);
string strValue = (char*)_bstr_t(vtNodeValue);
From testing, I believe that the default encoding is either Windows-1252...