Skip to main content
4 votes
1 answer
165 views

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 (...
Enlico's user avatar
  • 30.3k
2 votes
1 answer
130 views

I originally created a class like so: class A { public: void run(int x); private: void run_helper1(); void run_helper2(); void run_helper3(); int a_; double b_; bool c_; }; ...
jlev's user avatar
  • 31
0 votes
1 answer
114 views

(This question popped to my mind after reading this one and its accepted answer.) Assume a class Foo that you cannot modify, that has a public member bar, but no getter for it. You might want to write ...
Enlico's user avatar
  • 30.3k
1 vote
1 answer
706 views

I've got various classes: struct foo final { std::string toString() const { return "foo"; } }; struct bar final { }; std::string toString(const bar&) { return "<bar>"; } ...
Pam Patrick's user avatar
2 votes
2 answers
137 views

As the title suggests, I am wondering if I can call a non-member function (which is contained in the class header file) from inside the class, with the caveat that the nonmember function is using the ...
AssistantToTheRegionalManager's user avatar
2 votes
1 answer
710 views

According to cppreference, in Argument-dependent lookups function names are looked up in the namespaces of their arguments in addition to the scopes and namespaces considered by the usual unqualified ...
glades's user avatar
  • 5,374
0 votes
0 answers
27 views

I have a variable class that I am using to make scripting more easier in my program. I am trying to figure out an easy way to do something like the following: myclass { protected: int _data; ... }...
Chubby Monkey's user avatar
0 votes
0 answers
108 views

Lets say I implement some functions for type Foo. If they are member functions VS will offer them for a foo object but if I implement them as free / non-member functions then I get no help. foo....
Newline's user avatar
  • 983
10 votes
1 answer
308 views

I know the general use cases for the friend keyword with regards to encapsulation but one a couple of occasions, I have needed the friend keyword just to "get the job done". These use cases ...
user137364's user avatar
0 votes
0 answers
81 views

When having a look at the documentation of std::map, I noticed that the lexicographical comparison operators (between maps) were not counted as member functions. Checked a few other containers (vector,...
Caglayan Dokme's user avatar
1 vote
0 answers
24 views

I have searched for a specific answer for my question and i couldn't find one , so here is my question: I know that if we have operator+ and operator+= += should be a method and + a non-member ...
Raea6789's user avatar
  • 141
0 votes
1 answer
1k views

I've tried couple of weeks and searched for days for an answer, but haven't found it. My code is rather large and intertwined, but my problem is with 3 functions/classes, therefore I will only show my ...
Mihkel Rüütli's user avatar
0 votes
1 answer
270 views

So, I basically learnt class and also Template functions in C++. Suppose I have a record of students in a class with their roll number, name and total marks. I am using index sorting to sort the ...
rKA's user avatar
  • 3
-1 votes
1 answer
155 views

I want to add v2 to v1. My member function is working, but free function is not. How can I solve this problem, thanks. When I compile with: clang++ -std=c++2a hw1.cpp -o hw1 and run with: ./hw1 give 5 ...
emir's user avatar
  • 9
0 votes
1 answer
376 views

So I understood how to print a single linked list in reverse order using recursion. I'm having trouble with doing it non member functions. For example in int print_reverse(IntSLList & list)) ...
ghf's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
7