Felics

1

votes
2

answer
6.3k

views

API for capturing sound on Windows

I need a C++ API to enumerate input devices and capture sound for Windows Vista, Windows 7 and Windows 8. If there is no common API I can use OS specific API for different versions of Windows. I found some references on Microsoft site, but I don't know what to chose. What do you recommend?
Felics
1

votes
1

answer
1.7k

views

How to get gtest TYPED_TEST parameter type

I have some unit tests written on Windows (Visual Studio 2017) and I need to port them on Linux (GCC 4.9.2 - I'm stuck with this version...). I've come with a simple example for my problem which compiles fine on Windows (I don't think it should compile as MyParamType is a dependent type from e templ...
Felics
1

votes
1

answer
138

views

Mechanism to create “template” objects in C++

I want to be able to initialize objects with some default values, but to do this from external code(not embedded in the class itself). The objects are exposed to external editor and I don't want to set the same values again and again and change only some values that are different. As I have already...
Felics
1

votes
1

answer
173

views

C++ standard way to check if type has function with specific signature

This question is related to: Check if a class has a member function of a given signature Is this functionality implemented by C++11 standard or do I need to use custom implementation?
Felics
1

votes
1

answer
160

views

Get pointer to function declared into namespace

I wanted to count the spaces from a std::string. Very simple task for std::count_if so I wrote this code: std::cout
Felics
1

votes
2

answer
657

views

C++ algorithm to advance iterator while condition is true

Having a pair of iterators [begin, end) I want to advance begin while a condition is true and I didn't reach end. As I don't know any "direct" algorithm from the standard library to do this I'm using: std::find_if_not(begin, end, condition); but my problem is that the name of the function does't exp...
Felics
1

votes
1

answer
90

views

Order of destruction for stack/heap allocated arrays

Considering following code: struct A{...}; A a[100]; A* pa = new A[100]; delete[] pa; Is the order of destruction for the elements of a/pa defined by the standard or it is implementation defined (for the second case operator delete[] is not user defined).
Felics
1

votes
1

answer
197

views

Safe lock/unlock without scope guard

I have to deal with a design restriction(dependency issues) to not use scope guard for a mutex. Sample code: template class Test { MutexType myMutex; public: void f() { myMutex.Lock(); //code with many returns here depending on conditions myMutex.Unlock(); } }; Is there other safe way of dealing wi...
Felics
13

votes
2

answer
924

views

C++ const correctness with string literals [duplicate]

This question already has an answer here: What is the type of string literals in C and C++? 4 answers According to the C++ standard a string literal type is array of const char auto constStr = "aaa"; char* nonConstStr = constStr; //Error here, cannot convert from 'const char *' to 'char *' char* st...
Felics
1

votes
1

answer
185

views

C++ uniform initialization with default values

Considering following structs: struct A { int i; }; struct B { int i = 0; }; Why I can initialize objects of type A using uniform initializers and I can't initialize objects of type B? A a{1}; B b{1}; //ill formed What is the compiler doing when a default value is used to initialize members?
Felics
1

votes
4

answer
200

views

Signalize thread to start specific function

I want to split some CPU intensive jobs to multiple threads. I want to make a thread pool with, let's say, 4 threads. I want to know very fast ways to do following: Check if one thread is free for receiving processing Signalize one thread to start specific function Wait for all the threads to finish...
Felics
3

votes
1

answer
124

views

Qt refreshes at 60 FPS and eats GPU

I have a Qt application that starts refreshing at 60FPS, but I can't detect why. I used QML profiler and I can't see any event that triggers redraw. Using: QSG_RENDERER_DEBUG=debug QSG_RENDER_TIMING=1 I see Gui Thread: window=0x7fffffffe400, polish=0, lock=0, block/sync=15 -- animations=0 written...
Felics
20

votes
4

answer
26.5k

views

How to redirect stdout to output window from visual studio

Is it possible to redirect stdout to output window from Visual Studio? I use in my program OutputDebugString but I use some libraries that have output debug messages with printf's or cout's.
Felics
5

votes
4

answer
1.9k

views

C++ template function that receives std::vector as argument

I need to make a template function that receives as parameter a std::container of some type - let's say std::vector and deletes all elements from that container. I need a function equivalent to this: for_each(some_vector.begin(), some_vector.end(), [](some_vector_type* element){delete element;}); T...
Felics
5

votes
3

answer
345

views

Macro to repeat almost the same code

I have to write same code dependent on compile time constant parameter, something like: map["text 0"] = vec[0]; map["text 1"] = vec[1]; ... map["text n"] = vec[n]; The problem is that I don't know n when I'm writing the code, I receive it as template parameter. The obvious solution is to use one loo...
Felics
2

votes
2

answer
173

views

How to specialize template function with template types

Is it possible to specialize a template function for template types? I don't know if my terminology is correct, so I'll provide a simple sample with what I want to achieve: #include #include #include template void f() { std::cout
Felics
11

votes
5

answer
7.6k

views

The class foo can be designed, but is not the first class in the file error

I have this The class foo can be designed, but is not the first class in the file error after adding foo class derived from TextBox in my C# file. How can I pass it, it's very annoying. EDIT: I want to have multiple classes in my file. I want to have some classes derived from TextBox that accept spe...
Felics
11

votes
1

answer
2.9k

views

When is a function registered with atexit() called

I want to know if functions registered with atexit() are called before or after global variables are destroyed. Is this specified by the standard or implementation defined?
Felics
11

votes
2

answer
4.8k

views

Function signature as template parameter

Is it possible to achieve something like this: template class Test { public: //here I want operator () to respect the signature }; Test t1; //void operator()(int) Test t2; //void operator()(int, float) Return type is always void. I want to send as template parameter the function signature...
Felics
5

votes
2

answer
2k

views

Apple LLVM 5.0 pragma optimize

What is the equivalent of GCC's #pragma GCC optimize("O0") or VS's #pragma optimize("", off) in Apple LLVM 5.0 compiler? I need it to disable optimizations for just a section of code.
Felics
11

votes
3

answer
14.2k

views

What is the correct usage of std::unique_ptr while pushing into std::vector [duplicate]

This question already has an answer here: Why can I not push_back a unique_ptr into a vector? 2 answers I want to have a vector of pointers to objects in my class. To avoid making a destructor for it I wanted to use std::unique_ptr, as the objects are created/owned/destructed in my class, but I hav...
Felics
5

votes
1

answer
1.2k

views

How to disable implicitly-defined copy constructor generation when there is user defined destructor

Are there any compiler flags to enforce next rules? The generation of the implicitly-defined copy constructor is deprecated if T has a user-defined destructor or user-defined copy assignment operator. The generation of the implicitly-defined copy assignment operator is deprecated(since C++11) if T h...
Felics
22

votes
7

answer
14.2k

views

How to propagate friend for derived classes

I want to have a class hierarchy and be able to create objects from it only inside a Factory. Example: class Base { protected: Base(){}; virtual void Init(){}; friend class Factory; }; class SomeClass : public Base { public://I want protected here! Now it's possible to call new SomeClass from anywhe...
Felics
4

votes
5

answer
6.6k

views

p4v command line submit changelist

Is there any way to use command line to submit a changelist already created with p4v? May I open command line in p4v? I have a huge changelist and p4v gets stuck when I right click on it to chose submit and I want to use command line or something else to submit it. When I say huge changelist I mean...
Felics
2

votes
0

answer
1k

views

C interface to get documents folder on iOS

Now I use: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; to get Documents folder on iOS, but I would like to have C interface to keep file type as C/C++ instead of Objective-C/C++. Is it possible to get Documents path on iOS using only C functions? EDI...
Felics
3

votes
11

answer
5.2k

views

Is it possible to define a class in 2 or more file in C++?

I know it's possible to do class implementation in more than one file(yes, I know that this is bad idea), but I want to know if it's possible to write class definition in separate files without getting a redefinition error (maybe some tricks, or else...)
Felics
3

votes
1

answer
267

views

#define mockable virtual in C++

I found this code: #define mockable virtual Do you have any idea why somebody will define virtual like this? I'm just curios what's the point of doing this
Felics
3

votes
5

answer
2.3k

views

How to stop ReadDirectoryChangesW from other thread

I use next code to know when a files is changed in a certain folder: HANDLE hDir = ::CreateFile(path, FILE_LIST_DIRECTORY, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OVERLAPPED, NULL); FILE_NOTIFY_INFORMATION returnData[1024]; DWORD...
Felics
3

votes
2

answer
338

views

Identify type in a generic portable way in C++

Is there any way to identify a type in a generic and portable way for serialization? I know std::type_index and std::type_info are platform dependent and can't be used for serialization. One way would be to make a map between std::type_index and one "type information" and to serialize the "type inf...
Felics
5

votes
5

answer
4.9k

views

__attribute__((init_priority(X))) in GCC

I'm using __attribute__((init_priority(X))) in GCC like this: Type1 __attribute__ ((init_priority (101))) name1 = value1; Type2 __attribute__ ((init_priority (102))) name2 = value2; in different source files. Let's say file1.cpp and file2.cpp. If I use this in same library it works as expected, nam...
Felics
6

votes
2

answer
4.8k

views

iPad orientation returns unknown values

I use this code: UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; to get iPad orientation but it returns UIDeviceOrientationUnknown when I use OpenGL rendering. When I play movies or I display UIViews it return the correct value. Do you know how may I get correct orientation...
Felics
4

votes
3

answer
234

views

Question about enums in C++

I tried to use an enum in a for loop like this: enum foo { foo_0, foo_1, foo_2, foo_3, ... foo_n, foo_count }; for(foo f = foo_0; f < foo_count; ++f) and I had a compilation error. I understand that this is not valid because ++f might not be a valid foo enum - not in this case but in general case...
Felics
2

votes
2

answer
341

views

iPhone App has large memory footprint on startup

If I put a breakpoint on my first line of code from main function, I see in the activity monitor 17MB of memory for my app. Do you have any idea why the memory usage is so high without anything loaded? (Maybe the OS is loading many things, but not me) This memory usage has almost the same size as t...
Felics
3

votes
5

answer
2.2k

views

C++ template with float arguments [duplicate]

Possible Duplicate: C++: Why can’t I use float value as a template parameter? I have this class: template class SomeClass { public: SomeClass() : m_value(DefaultValue){} ValueType m_value; }; I want to use it like this: SomeClass intObj; //ok SomeClass floatObj; //error: 'float' : illegal type fo...
Felics
4

votes
1

answer
672

views

Exposing member variables methods in C++

I have a simple Object-Components design. Something like: class Object1 : public Object { Component1 _comp1; Component2 _comp2; ... ComponentN _compN; }; Is it possible to expose as public: methods of Objects1 some methods from ComponentK without creating a method in Object1 that calls internally Co...
Felics
4

votes
1

answer
644

views

Compile time map “search” in C++

I have next simplified callbacks map. Please excuse me if the code contains some erros, but it's a very simplified version of actual code to be able to reproduce it here. struct CallbacksMap { template void Add(T* obj, void (T::*objCallback)(const U&)) { CallbackBaseType* c = new CallbackType(obj, o...
Felics
6

votes
3

answer
3k

views

Why do I get these warnings in Visual C++ 2008 when building a struct?

I have this code typedef struct { const char* fooString; const bool fooBool; }fooStruct; And this initializer: static const fooStruct foo[] = { {"file1", true}, {"file2", false}, .... }; With this code I have 3 warnings in VS2008: error C2220: warning treated as error - no 'object' file generated...
Felics
2

votes
3

answer
1.2k

views

C++ unsequenced modifications for iterators

I have next code in one unit test for iterators: EXPECT_TRUE(++it != it++); Where it respects std iterator requirements. As far as I know 2 modifications of the same variable in the same sequence point is undefined behavior(!= is not sequence point). Considering both operator++ versions are functio...
Felics
3

votes
2

answer
449

views

atan2f precision on xcode

I have this very simple code: #include #include int main(int argc, const char * argv[]) { printf("%2.21f", atan2f(0.f, -1.f)); return 0; } With next output on Intel CPUs: Visual Studio 2010: 3.141592741012573200000 GCC 4.8.1 : 3.141592741012573242188 Xcode 5 : 3.14159250259399414...
Felics
3

votes
2

answer
944

views

Using offsetof for template classes

From the C++ standard: A standard-layout class is a class that: — has no non-static data members of type non-standard-layout class (or array of such types) or reference, — has no virtual functions (10.3) and no virtual base classes (10.1), — has the same access control (Clause 11) for all non-...
Felics

View additional