c++

Macro-based counter

倖福魔咒の 提交于 2021-02-19 07:43:26
问题 Is it possible to create compile time constants like this: // event.h #define REGISTER_EVENT_TYPE() ... // Returns last_returned_number+1 // header1 #define SOME_EVENT REGISTER_EVENT_TYPE() // header2 #define SOME_OTHER_EVENT REGISTER_EVENT_TYPE() Where SOME_EVENT will be 0 and SOME_OTHER_EVENT will be 1. Tried the following code: #define DEF_X(x) const int x = BOOST_PP_COUNTER; #define REGISTER_EVENT_TYPE(x) BOOST_PP_UPDATE_COUNTER()DEF_X(x) #include REGISTER_EVENT_TYPE(SOME_EVENT_TYPE) But

Macro-based counter

狂风中的少年 提交于 2021-02-19 07:43:25
问题 Is it possible to create compile time constants like this: // event.h #define REGISTER_EVENT_TYPE() ... // Returns last_returned_number+1 // header1 #define SOME_EVENT REGISTER_EVENT_TYPE() // header2 #define SOME_OTHER_EVENT REGISTER_EVENT_TYPE() Where SOME_EVENT will be 0 and SOME_OTHER_EVENT will be 1. Tried the following code: #define DEF_X(x) const int x = BOOST_PP_COUNTER; #define REGISTER_EVENT_TYPE(x) BOOST_PP_UPDATE_COUNTER()DEF_X(x) #include REGISTER_EVENT_TYPE(SOME_EVENT_TYPE) But

Multiple definition of namespace::variable even using ifndef

十年热恋 提交于 2021-02-19 07:40:07
问题 I know I must be doing something wrong here. rank.h #ifndef RANK_H #define RANK_H namespace mmi { int chunk; void rank(int my_rank); } #endif rank.cpp #include "rank.h" namespace mmi { //do something with chunk } main.cpp #include "rank.h" int main() { mmi::chunk = 1; } And the output of compilation; g++ -g -Wall -std=gnu++11 -c -o main.o main.cpp g++ -g -Wall -std=gnu++11 -c -o rank.o rank.cpp mpic++ main.o rank.o -o main rank.o:(.bss+0x0): multiple definition of `mmi::chunk' main.o:(.bss

Boost:spirit Parsing into structure and reusing parts of it

对着背影说爱祢 提交于 2021-02-19 07:38:23
问题 I have to find variables in a sentence and replace them by their value. Variables can be written in different forms, like $varName, or $(varName) for example. I'd like to have a struct VariableHolder to have easy access to both : struct VariableHolder { string name; // contains "varName" string fromFile; // contains "$(varName)" or "$varName" void setName(ustring n) { name = n; } } Obviously, I'd like to avoid doing multiple passes and calling multiple parsers. What I have so far is this :

DirectShow manual graph memory leaks

依然范特西╮ 提交于 2021-02-19 07:31:09
问题 Here is simple capture and render graph build manualy. CaptureFilter->SmartTee->(preview)->AviDecompressor->Render All works well and gets 140Mb while working. After I Stop the render and Release all filters and IGraphBuilder 50Mb remaining! Again build same filter - all works but 140+50=190Mb in ram. After release 100Mb remaining. And again and again. I had try SmartPtr, ComPtr, Release() in any imaginable combinations but no effect. Seems I do something compleetly wrong :( #include <windows

When compiling code antivirus says it's virus and delete it

做~自己de王妃 提交于 2021-02-19 07:30:53
问题 Hi i try to make code in c++. This code only makes text file easy encrypted and save into a new file. And when i compile this code antivirus says, it is virus/spyware Gen:Variant.Kazy.20825. I dont know why it is virus. Here is my code: #include <iostream> #include <fstream> #include <string> using namespace std; void controlParameters(int argc){ //check if input parameters are ok if(argc == 1){ cout << "Pokud chcete text zasifrovat, spustte program s parametrem: -enc \"Nazev_souboru.txt\"\n"

get char on screen

早过忘川 提交于 2021-02-19 07:10:40
问题 I've looked through the NCurses function list, and I can't seem to find a function that returns the characters already printed on the screen. Is there an accessible value for the char stored in each character cell? If not, is there a similar function in the Windows terminal? I want to use this to replace all the characters on the screen of a certain value (ex: all the a 's) with a different character, or with new attributes. 回答1: The function inch() gets the character and returns it as a

Makefile Dependencies, What Should Be a Dependency?

冷暖自知 提交于 2021-02-19 06:57:08
问题 I have a conceptual question regarding makefile dependencies and this is because I see inconsistency online about this. Let's say I have the following files: main.cpp uses-> my_math.cpp and my_strings.cpp my_math.cpp uses-> my_math.h my_strings.cpp uses-> my_strings.h If I have a makefile, with the general outlay of: program: $(all_objs) g++ $(all_objs) -o program main.o: ... ....... my_math.o: ... ....... my_strings.o: ... ....... I don't know what should go into each dependency. Like, math

How to correctly clone a string from a struct in a C library into a new memory address?

三世轮回 提交于 2021-02-19 06:48:05
问题 I'm trying to make a clone of my C++ object, which is a wrapper around a C 'class'. I want to API to look like this: LibrdfUri uri("http://uri.com"); LibrdfUri uri_clone = uri.clone(); // same value but points to different memory address Here is my clone function ... librdf_uri *LibrdfUri::get() const { // librdf_uri is the C type that I am wrapping return librdf_uri_.get(); // librdf_uri_ is a unique pointer. .get returns the raw pointer } LibrdfUri LibrdfUri::clone() const { unsigned char *

How do you declare a ranges-v3 view return value?

喜欢而已 提交于 2021-02-19 06:35:11
问题 Currently, I can compose ranges-v3 views like this: auto v = ranges::view::reverse | ranges::view::filter([](int l){return l>5;}); But if I wanted to return v from a function I'd need to know its type. What is the type of a ranges-v3 view? 回答1: Since C++14 you can use auto as the return type of functions and it will get deduced: auto f() { return ranges::view::reverse | ranges::view::filter([](int l){return l>5;}); } // f's return type is the type of the return expression, exactly as is I had