Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
44 views

Here is my simplified code: S.h class SBase { ... public: virtual std::vector<int32_t> getNumbersSet1(); virtual std::vector<int32_t> getNumbersSet2(); } class SDerived : public ...
jambodev's user avatar
  • 361
14 votes
2 answers
805 views

I'm encountering unexpected behavior on MSVC when storing a pointer to a virtual method in a static inline variable. The issue does not occur on GCC or Clang. Specifically, when I store a pointer to a ...
Artem Selivanov's user avatar
3 votes
1 answer
78 views

I'm trying to create sort of an event system, I don't care if it is suboptimal, I'm doing it for fun. I do not want alternate solutions, I want to understand why this isn't working and how could I fix ...
Eric111's user avatar
  • 55
-1 votes
2 answers
220 views

Here is the error in GCC (which i have already fixed): ISO C++ forbid taking the address of a bound member function to form a pointer to member function This is the error line of my code: threads[i] ...
stirner's user avatar
8 votes
2 answers
196 views

Consider a base class with a couple of public fields and a derived class which inherits the base privately and makes one of the inherited fields public via the using declaration. I need to access this ...
Kaiyakha's user avatar
  • 2,075
-1 votes
1 answer
116 views

I recreated small example of a problem I'm seeing. I have two classes. Class Owner has a member variable, a. Class Client has a member variable which references the member variable a from the Owner ...
Keegan's user avatar
  • 19
0 votes
0 answers
48 views

I think this question is related to C++ pointer to member of derived class, but slightly different. I have a class accepts a pointer-to-member as template parameter, and will deduct the holder's type ...
blackcloud's user avatar
0 votes
2 answers
101 views

I am trying to port C code to a C++ program and thus encapsulate the logic from the C program inside a C++ class. The step I am stuck at is using a function pointer, which is a field inside a struct ...
Mario Christov's user avatar
0 votes
1 answer
88 views

A pointer to member function isn't a regular pointer. but a pointer to a pointer to member function does. struct X { void func() {} }; int main() { auto p1 = &X::func; auto p2 = &...
Benny Hu's user avatar
1 vote
1 answer
58 views

I'm trying to create a notebook program cpp file: #include <string> #include "Menu.h" class Notebook { std::vector<std::string> m_notes; public: void addNote() { ...
Svyat's user avatar
  • 79
1 vote
1 answer
127 views

class Harl { private: void debug( void ); void info( void ); void warning( void ); void error( void ); public: void complain( std::string level ); }; ...
MAROUAN's user avatar
  • 13
1 vote
0 answers
55 views

I have to implement a low-level interface for the library which exposes structure with a function pointers like this: struct Interface { int (*IterfaceFn) (int value); }; Library then expects a ...
sokzmalin's user avatar
0 votes
1 answer
75 views

I have a class with overloaded method: #include <iostream> #include <utility> struct Overloads { void foo() { std::cout << "foo" << std::endl; } ...
Георгий Гуминов's user avatar
2 votes
1 answer
84 views

I would like to have a base class that I derive from that offers serialization mechanism: template <typename Type, typename Class, Type Class::* Member> class Serializable { public: void ...
Jeffrey's user avatar
  • 11.1k
0 votes
3 answers
173 views

I have structure typedef struct { int i; float f; } S; The rules for mutual conversions between pointers to a structure and its first member say that I can write like this S s; int *pInt = (int ...
Evgeny Ilyin's user avatar
0 votes
0 answers
34 views

This doesn't execute any suggestions: void (CClient::*pMethod[CNetwork::ClientEvent::E_CE_MAX_EVENTS])(); pMethod[CNetwork::ClientEvent::E_CE_ACCEPTED] = &CClient::Accepted; pMethod[CNetwork::...
developer68's user avatar
1 vote
1 answer
129 views

Consider this class: template <typename T> struct Buffer { template <typename Field> int add_member_attribute( std::string&& name, Field T::* ...
trbabb's user avatar
  • 2,135
0 votes
0 answers
61 views

In this so question about sorting only some fields in a std::vector of struct, this interesting answer was provided: std::vector<SimpleStruct> vs = {{1, 10, 11}, {5, 100, 111}, {3, 1000, 1111}}; ...
Oersted's user avatar
  • 3,834
0 votes
1 answer
100 views

I hope someone can help me since can't quite understand how it is possible that the following code can work. I have a base class with some classes that derive from it. Each derived class has its own ...
lightimpact90's user avatar
0 votes
1 answer
114 views

In Arduino projects, I often find that I need to have some class call a callback function when something happens, for instance when a pin reaches a certain value, or when a certain amount of time has ...
Bas's user avatar
  • 2,038
1 vote
1 answer
87 views

I want to be able to defer calls to member functions of some object. Therefore, I need to be able to store member function pointers plus parameters as data. My approach uses C++ templates that treat ...
EsGeh's user avatar
  • 41
4 votes
3 answers
188 views

I've got interested in one thing - in c++ we have pointers to data member, for example: struct A { int a_1 = 1; }; A a; int A::* p_a = &A::a_1; a.*p_a = 10; But if I have something like ...
Ultra_Igor's user avatar
0 votes
1 answer
626 views

It seems a difficult thing to do in C++. A callback to a member function in a class in C style, thus making this a void(*)() to be able to use this in a C-style callback function. In this case I want ...
Martin Maters's user avatar
1 vote
1 answer
149 views

So I sort of tried to accomplish “the impossible” at least in C++20 and with the constraint that the class for which I am extracting a member function pointer can be evaluated as a constexpr. #include ...
jamadagni's user avatar
  • 1,276
0 votes
1 answer
177 views

I have a structure with several members of unsigned short type. The values stored in these types should be in a certain range, so I use a setter method for them that checks the range of the value ...
hdmi87's user avatar
  • 1
-1 votes
1 answer
93 views

struct CALLBACK_DATA { Object *pointer; void (Object::*callback)(); }; int main() { CALLBACK_DATA data = getData(); //This isn't working. (data.pointer)->(data.*callback)(); } ...
Praveen Kumar's user avatar
1 vote
1 answer
66 views

At the moment I have a problem. I want to replace the interrupt vector target call for a peripheral driver. What works for now is this: namespace test { class PortDriver{ public: using ...
tunguskar's user avatar
-1 votes
1 answer
99 views

Here is a linked list: #include <iostream> #include <iomanip> #include <string> using namespace std; struct Arrival { string arrAddress; double distance; string ...
Roman's user avatar
  • 21
-1 votes
1 answer
105 views

I have created a Camera class containing a keymap of std::map<int, void(Camera::*)() to facilitate an in-game option for key bindings and higher performance key-action lookup than what could be ...
HeyoItsMateo's user avatar
0 votes
1 answer
137 views

I have one class Hunter that has a member function random_hunt which returns a pair<int, int> const that's supposed to be equivalent to some point (x, y). I'm trying to implement a second member ...
Nathan Xu  's user avatar
2 votes
2 answers
111 views

I was trying to get "more fluent" with function pointer manipulation and I've got an issue with passing a member function to std::function when there are two overload: const and non-const. ...
Oersted's user avatar
  • 3,834
3 votes
1 answer
169 views

I often work with C-style libraries, where the callback-and-opaque-pointer pattern is common: void callback(void *user_data, ...) { ... } register_callback(callback, ptr_to_something_useful); When ...
TypeIA's user avatar
  • 17.4k
0 votes
1 answer
52 views

How I can add what characters I want to the end of what the user would type in. Also a pointer is being passed into the wordArr[] if that helps at all #include <iostream> #include <string> ...
3u4ia's user avatar
  • 23
2 votes
2 answers
113 views

I have a class which derives from another class who implements a map of callback functions. I need to pass pointers to the callback from the child to the parent but I get compilation conversion errors....
Ori Tsachi's user avatar
0 votes
2 answers
52 views

How do I pass the non-static member function eval of object Problem1 obj to the object Solver solver ? #include<iostream> #include<functional> // non-templated class struct Solver{ ...
user avatar
0 votes
2 answers
113 views

I have problem in this line std::cout << &X::a << std::endl; this line print 1 supposed to printed address of &X::a this my code #include <iostream> #include <string>...
Hassan Lakhal's user avatar
0 votes
2 answers
550 views

I'm not able to understand what this error means, and what is causing it. Here is my code, please help me to point out the mistake: class Solution { public: bool sortbysec(const pair<int,int>...
Krishna Gaggar's user avatar
1 vote
2 answers
88 views

I have here a minimized version of code below, that won't compile. #include<iostream> #include<vector> #include<set> template<int D> class Points{ public: std::vector<...
Prapanch Nair's user avatar
2 votes
2 answers
215 views

I am trying to generalize a function for a game engine I am writing to simplify the shader loading process. Anyway, the difficulty arises in my attempts to templating the function. I attempted to ...
ModernEraCaveman's user avatar
1 vote
1 answer
119 views

I am trying to use something like a strategy pattern, where there are two different Parsers Type1Parser and Type2Parser using an interface IParser. There is another class ParsingText where we have 2 ...
Johnson Jose's user avatar
0 votes
1 answer
488 views

I am trying to implement a function that sets a struct member and also serializes the data to an external output. For serialization purposes, I need to know the size and offset of the struct member, ...
Armandas's user avatar
  • 2,416
0 votes
0 answers
20 views

I was utilizing a map of function pointers with different option values as follows in my main.cpp file for different menu items: int main() { while(true) { printMenu(); int ...
qxzsilver's user avatar
  • 665
2 votes
1 answer
161 views

I would like to create a function-object class that numerically integrates some functions on-demand. Its public interface would consist of a method void T::step(double dt) that computes an integration ...
impresso's user avatar
  • 209
2 votes
3 answers
517 views

I have a member funtion like this: class Foo { public: template<typename... Args> static void bar(const Args&... args) { /* code */ } }; And I want to pass it as a template ...
Luh0's user avatar
  • 105
0 votes
2 answers
159 views

I'm trying to implement subscriber-publisher pattern. My base class Subscriber doesn't have a listener method, it declares type Handler instead. The idea behind this is that a derived class will be ...
DENIS KOVALENKO's user avatar
2 votes
0 answers
79 views

I have a function that takes a pointer to a member function (along with the necessary arguments) and calls the function on a class instance. Is there a way to not have to pass the default arguments or ...
SMMB's user avatar
  • 137
2 votes
0 answers
64 views

With a class definition, an object pointer and a pointer-to-member, it is possible to obtain an absolute pointer to that member: class X { public: int a { 0 }; int b { 1 }; int c { 2 }; }; ...
Kai Petzke's user avatar
  • 3,152
1 vote
3 answers
623 views

How to implement a template that gets a class and a pointer to a member of this class? I want to template a sort of Accessor of the form template<??? T, ??? P> class Accessor { // ... T&...
André Caldas's user avatar
0 votes
0 answers
31 views

I know that C++17 introduced template< auto >, but the following example doesn't use it, yet still only compiles in C++17: struct Foo { int bar; }; template< int Foo::* > void ...
dragonroot's user avatar
  • 5,911
0 votes
1 answer
458 views

I am trying to create object of another class in one class (I am able to do this) and I want to pass a method of the first class to the second class as constructor argument (I am not able to do this. ...
Dheeraj Singhal's user avatar

1
2 3 4 5
21