c++

Sizeof of derived class with virtual constructor

During job interview, I’ve been overwhelmed by this question: bool Res – what it shows to us? template <class T> class R { class A: public T { virtual ~A(){} }; public: static const bool Res = sizeof(A) == sizeof(T); }; During my investigation – I’ve always had sizeof(T) == 1, while sizeof(A) varies. Explanation will be very appreciated. …
Read more

Mouse click sending me message multiple times in c++

This is my code:- DWORD WINAPI ThreadMouse(void* data){ while (1){ //Check the mouse left button is pressed or not if ((GetKeyState(VK_LBUTTON) & 0x8000) != 0) { MessageBox(NULL, L”Left Clicked”, L””, NULL); break; } //Check the mouse right button is pressed or not if ((GetKeyState(VK_RBUTTON) & 0x100) != 0) { MessageBox(NULL, L”Right Clicked”, L””, NULL); break; } } return 0; }…
Read more

Why does Local variables that are not explicitly initialized are automatically initialized to zeroes [on hold]

It is defined in many places that local variables that are not explicitly initialized are left uninitialized and have an undetermined value. But I tried to check this on different compilers and machines and in all of them they are automatically initialized to zero. Why? I mean, aren’t they supposed to be uninitialized and have undetermined values? Is it a…
Read more

Xcode not reading ~/.lldbinit

Xcode 6.4 does not stop on breakpoints in files that are #included in the main.cpp file. This is a C++ “command line tool” created in Xcode new project wizard. To fix this I’ve tried what’s suggested in the SO threads here, here and here. That is, I’ve added a ~/.lldbinit file with settings set target.inline-breakpoint-strategy always, I’ve created another one…
Read more

Multi-monitor aware application: disable windows automatic monitor configuration

OS: Windows 8 Hi all, my application works using a specific hardware involving a main monitor (that is always the same) and an HDMI port that can be used to add a secondary monitor. I need to manually configure the monitors configuration. For example I don’t want to change the main monitor resolution allowing the clone mode only if the…
Read more

How to create configuration for only one project in solution

I have a Visual Studio c++ solution that contains multiple projects: MainLib (lib that uses other libs) Lib1 Lib2 … I have standard configurations: ‘Release’ and ‘Debug’. Now I created new configuration ‘Test’ and I want this configuration to be used in MainLib (for unit tests only). Is it possible to use ‘Debug’ configuration in Lib1,Lib2… when ‘Test’ is active…
Read more

why Android NDK log.h __android_log_print linker error

I tried to use __android_log_print. But I getting linking error. I used makefile Android.mk :- LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := com_test_JniTest.cpp LOCAL_MODULE := com_test_JniTest LOCAL_LDLIBS += -llog include $(BUILD_SHARED_LIBRARY) I get error as :- /Users/abc/AndroidStudioProjects/Test/app/src/main/jni/com_test_JniTest.cpp Error:(29) undefined reference to `__android_log_print’ So how to link and use __android_log_print ? Source: c++

Why does cin.getline() not work (C++)? [duplicate]

This question already has an answer here: Using getline(cin, s) after cin 6 answers #include <iostream> using namespace std; int main(int argc, char** argv) { char text[200]; int input; cin>>input; if (input == 1) { cin.getline(text, 200); cout<<text<<“n”; } else if(input == 0) { cout <<“You entered a 0”; } return 0; } I am trying to make a small…
Read more

Convert unsigned int formatted in HEX to string

I am developing a hmac-sha1 class for my exam. I’ve a problem when I have to apply sha-1 two times as described in https://en.wikipedia.org/wiki/Hash-based_message_authentication_code. When I apply sha1 to a string, it returns me a unsigned int [5] with the hash calculated. I want to convert unsigned int [5] into a char [40] with the hash. For example unsigned int…
Read more

Bytes to signed short

I get two bytes, for example 0xFE and 0x70, it should represent the value of -400. How could I convert those bytes to signed short? Is it even possible? Source: c++