member-functions Questions

3

Solved

How do I call invoke_result correctly for a member function? Or specifically for an operator member function. I tried std::invoke_result<T::operator[], size_type> to no success. What would be...

1

Solved

From the C++ standard working draft: Default constructors ([class.default.ctor]), copy constructors, move constructors ([class.copy.ctor]), copy assignment operators, move assignment operators ([c...

3

I have this class template template <typename T> class Wrapper { public: virtual void parse(std::string s) = 0; protected: T value; }; ideally, each type should know how to parse itse...

2

Solved

Is it possible to have a class with an optional template parameter that can be called like this?: #include <iostream> template <typename T = void> class A final { public: // This clas...
Sperry asked 26/9, 2023 at 13:8

11

Solved

How do I obtain a function pointer for a class member function, and later call that member function with a specific object? I’d like to write: class Dog : Animal { Dog (); void bark (); } … Dog...
Bankroll asked 28/9, 2009 at 8:30

6

Solved

I can easily bind member functions to a std::function by wrapping them with a lambda expression with capture clause. class Class { Class() { Register([=](int n){ Function(n); }); } void Regi...
Transpacific asked 16/6, 2013 at 9:17

6

Solved

I'm relatively new to Python and struggling to reconcile features of the language with habits I've picked up from my background in C++ and Java. The latest issue I'm having has to do with encapsu...
Louanneloucks asked 9/4, 2012 at 10:58

1

Solved

I have a C++ function that takes a std::function as an input argument. Specifically, a std::function<void (const Message&, Error)>. In my use-case, the caller may bind the std::function t...
Gobble asked 26/4, 2023 at 20:10

1

A member function pointer must be invoked using the .* (or ->*) syntax, so it can't be passed to a higher-order function: #include <vector> void for_each(auto const& v, auto f) { for...

1

Solved

I was trying to take address of templated member function instance. For some reason, it is not working. Here is minimal reproducible example: class X { public: template<bool B> inline voi...

15

Solved

Suppose I have two C++ classes: class A { public: A() { fn(); } virtual void fn() { _n = 1; } int getn() { return _n; } protected: int _n; }; class B : public A { public: B() : A() {} vi...

3

Solved

In this link : Implicit object parameter In this quote : If any candidate function is a member function (static or non-static) that does not have an explicit object parameter (since C++23), but n...

12

What is the meaning of const in declarations like these? class foobar { public: operator int () const; const char* foo() const; };

2

Solved

Consider a class Bar in two versions of a library: /// v1 class Bar { void get_drink() { std::cout << "non-const get_drink() called" << std::endl; } }; /// v2 class Bar ...
Inutile asked 21/9, 2021 at 3:42

8

Solved

I'd like to set up a function pointer as a member of a class that is a pointer to another function in the same class. The reasons why I'm doing this are complicated. In this example, I would like ...

3

Solved

I have a basic question related to multiple inheritance in C++. If I have a code as shown below: struct base1 { void start() { cout << "Inside base1"; } }; struct base2 { void start() { c...
Castellated asked 27/7, 2011 at 14:10

3

Solved

I'm learning Python and have two files in the same directory. printer.py class Printer(object): def __init__(self): self.message = 'yo' def printMessage(self): print self.message if __name_...
Alkyd asked 30/7, 2017 at 1:52

2

Solved

I currently have two unnamed classes defined in my Foo.h: class Foo { public: Foo(); class { private: int x; int y; public: int GetX() { return x; } int GetY() { return y; } } Sub1; cl...
Pushed asked 20/5, 2015 at 15:30

3

I have a class with a member function with a lengthy return type: /* MyClass.hpp */ namespace foo { class MyClass { public: SomeNameSpace::Lengthy_return_type_name someFunction(params...); }...
Unsightly asked 9/10, 2020 at 6:47

4

Solved

I have a template class and a member function print() to print the data. template<typename T> class A { public: T data; void print(void) { std::cout << data << std::endl; ...

4

Solved

How do I get the absolute address of a member function in C++? (I need this for thunking.) Member function pointers don't work because I can't convert them to absolute addresses (void *) -- I need...
Shaylynn asked 14/11, 2011 at 12:6

8

Solved

I am confused on how to separate implementation and declarations code of a simple class into a new header and cpp file. For example, how would I separate the code for the following class? class A2...
Serge asked 6/3, 2012 at 8:5

2

Solved

I have a function like this: void f(std::ofstream& ostrm) { auto a = Myglobal->getData1(); ostrm << a; auto b = Myglobal->getData2(); ostrm << b; auto c = Myglobal-&gt...
Turney asked 17/10, 2019 at 7:38

4

I've been writing C++ code for a while now, but there's something I've been wondering for some time, without being to find a clear answer. My point here is the following: let's say I have a functi...
Analects asked 13/6, 2019 at 11:49

2

In Swift, an extension is a way to define members for classes after the fact. Or, you could say, it is (coming from a total newb) fancy way of composing a function: extension Double { var mm: Dou...
Salliesallow asked 8/5, 2016 at 20:51

© 2022 - 2025 — McMap. All rights reserved.