I want to have a static global std::unordered_map in the cpp of my entry point for my COM server.
relevant header code:
typedef unordered_map<HWND,IMyInterface*> MyMapType;
relevant body:
static MyMapType MyMap;
void MyFunction(HWND hWnd, IMyInterface* pObj){
MyMap[hWnd] = pObj;
}
HINSTANCE g_hInstModule = NULL;
BOOL WINAPI Dl...
I found the following C++ code (comments added myself):
// frame_name is a char array
// prefix is std::string
// k is a for loop counter
// frames is a std::vector string
sprintf(frameName, "%s_%0*s.bmp", prefix.c_str(), k, frames[k].c_str());
I then try to translate it to C#
// prefix is string
// k is a for loop counter
// frames ...
I have this snippet of the code
char *str = “123”;
if(str[0] == 1) printf("Hello\n");
why I can't receive my Hello thanks in advance!
how exactly compiler does this comparison if(str[0] == 1)?
...
I'm trying to implement line thickness as denoted here:
start = line start = vector(x1, y1)
end = line end = vector(x2, y2)
dir = line direction = end - start = vector(x2-x1, y2-y1)
ndir = normalized direction = dir*1.0/length(dir)
perp = perpendicular to direction = vector(dir.x, -dir.y)
nperp = normalized perpendicular = perp*1.0/leng...
What's the difference between async_read and async_receive?
...
I am creating a WIN32 application and I want most of all my application events to be made through the message queue. But everytime I create a dialog box or any resource like that. The IDE auto generates code that I don't necessarily need. I believe it's MFC code not sure. here it is.
// dlgChangeDevice.cpp : implementation file
//
#in...
I realize this is a ludicrous question for something that takes less than 2 seconds to implement. But I vaguely remember reading that one was introduced with the new standard.
I grep'ed VC10's headers and came up with nothing. Can you help? It's bugging me! :)
edit:
On second thought, the new functor I was remembering was probably the ...
I'm trying to understand whay i get an error on this code:
(the error is under g++ unix compiler. VS is compiling OK)
template<class T> class A {
public:
T t;
public:
A(const T& t1) : t(t1) {}
virtual void Print() const { cout<<*this<<endl;}
friend ostream& operator<<(ostream& out, const A<T>& a) {
out<<"I'm ...
Hi,
I am looking for a C++ library for image processing. I need the library to threshold a PPM photo (color photo). Should I write my own code? what do you guys think? Thanks in advance.
...
New to pthread programming, and stuck on this error when working on a C++&C mixed code.
What I have done is to call the c code in the thread created by the c++ code. There is a static boolean pointer is_center used in the thread and should got free when the thread finishes.
However I noticed that every time when the program processed...
I don't know if this is possible but, I have a class and I'v made an instance of it. I also put things in it. It has vectors and other things. I was wondering if I could save its contents (the instance) to a binary file, then reload it and cast it in from the file. Thanks
...
I have an OpenGL scene with a top left coordinate system. When I glScale it zooms in from (0,0) the top left. I want it to zoom in from the mouse's coordinate (reletive to the OGL frame). How is this done?
Thanks
...
What was the rationale behind introducing protected access specifier in C++. An example would be helpful.
...
If funciton overloading and templates serve more the less the same purpose then which one should we go for templates or function overloading and what are the corresponding benefits.
...
Is there a difference between a class template and template class. If so what is it?
...
Does this piece of code lead to dangling pointer. My guess is no.
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
}
int main()
{
Sample s1 = 10;
SomeFunc(s1);
s1.Pri...
new and delete are said to be preprocessors while malloc and free are functions. What is meant by new and delete being preprocessors?
...
What are some tips I can use to avoid memory leaks in my applications? In my current project I use a tool "INSURE++" which finds the memory leak and generate the report.
Apart from the tool is there any method to identify memory leaks and overcome it.
...
I'm sure everyone knows the joys of concurrency when it comes to threading.
Imagine the following scenario on every page-load on a noobily set up MySQL db:
UPDATE stats SET visits = (visits+1)
If a thousand users load the page at same time, will the count screw up? is this that table locking/row locking crap? Which one mysql use.
...
I was playing around a bit with functions with variable arguments, and decided to make a function to create vectors with the arguments. My function for creating an int vector worked...
vector<int> makeIntVector(int numArgs, ...) {
va_list listPointer;
va_start(listPointer, numArgs);
vector<int> made;
for(int a = 0; a < n...