Category : c++

Not very much accustom to Objective C, hence trying to observe NSWorkspaceDidActivateApplicationNotification event in C++ code with CFNotificationCenterAddObserver() method. #include<CoreFoundation/CFNotificationCenter.h> #include<iostream> #include<QGuiApplication> void Callback (CFNotificationCenterRef center, void* observer, CFNotificationName name, const void* object, CFDictionaryRef userInfo) { std::cout << "Hello Worldn"; //NSLog(@"New application: %@", [[name userInfo] objectForKey:NSWorkspaceApplicationKey]); } int main (int argc, char** argv) { QGuiApplication ..

Read more

I have some c++ code that defines a struct: struct IcmpHdr { uint8_t m_type; uint8_t m_code; uint16_t m_chksum; uint16_t m_id; uint16_t m_seq; } __attribute__((packed, aligned(2))) I understand that this struct will always be aligned on an address divisible by 2 when allocated because a padding byte ahead of the struct will be added if necessary. ..

Read more

I have a class DoorTerminal with a member function getInput() as shown below. DoorTerminal::DoorTerminal(DialogueBox *dialogue_, Door* door_): DialogueInterfacing(dialogue_){ emptyFor.push_back(string("Player")); type.push_back(string("DoorTerminal")); type.push_back(string("DialogueInterfacing")); imgpath = "/vagrant_data/Skeleton-game/src/sprites/terminal.png"; typestring = "DoorTerminal"; door = door_; } void DoorTerminal::getInput(){ string input = dialogue->getInput(); if(input == "1234"){ door->unlock(); } } I’m trying to create an instance of this class inside a function ..

Read more

I have a data structure S defined as: vector<vector<int>> S; At some point I Want to access S[i][j] in a forloop . But first I want to check that it exists so I am doing: for(int i = 1; i<S[i].end(); i++){..} S[i] is supposed to be of type vector<int> so I guess it’s valid to ..

Read more

I am trying to manage prioritized resource access of a camera in an embedded system. Therefore I made a camera interface which uses a std::condition_variable to realize this. typedef std::function<void()> UnlockCameraHandler; class Camera { const int MAX_PRIORITY = std::numeric_limits<int>::max(); int currentPriority = MAX_PRIORITY; bool mLockable = true; UnlockCameraHandler mUnlockCameraHandler; std::condition_variable_any cameraLock; std::mutex cameraMut; public: bool ..

Read more