non-member-functions Questions
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
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...
Storz asked 23/2, 2023 at 19:54
1
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 cas...
Christology asked 20/12, 2021 at 6:43
3
Solved
The situation is that some member function bar::Bar::frobnicate wants to utilize ADL to find a function from some unknown namespace, within a function that has an identical name. However, it only f...
Benedicto asked 24/7, 2013 at 6:1
2
Solved
Taking this example: https://godbolt.org/z/gHqCSA
#include<iostream>
template<typename Return, typename... Args>
std::ostream& operator <<(std::ostream& os, Return(*p)(A...
Valenta asked 17/1, 2020 at 1:13
3
Solved
It seems that the way that most people find the size of a string is they just use the my_string.size() and it works fine. Well, I recently did an assignment for class where I did...
if (size(my_st...
Epiphytotic asked 30/10, 2015 at 18:26
3
Solved
Background Info
I've been programming in Java for a while, and I've only switched over to C++ just a few months ago, so I apologize if the answer is just something silly that I missed! Now that th...
Calliopsis asked 19/11, 2014 at 19:28
2
Solved
I have a templated class, Iterable; for which I want to overload the begin() and end() free functions. It stores data as a vector of unique_ptr, but the interface uses boost::indirect_iterator for ...
Gombroon asked 20/10, 2014 at 10:19
1
Solved
Consider a legacy class template with overloaded addition operators += and +
template<class T>
class X
{
public:
X() = default;
/* implicict */ X(T v): val(v) {}
X<T>& operator...
Sacculus asked 28/9, 2014 at 20:10
3
Solved
Simple question, here: what is the difference between a static member function, i.e. a function that can be called without requiring an object to access it (simply using the class identifier)...
Antennule asked 22/4, 2014 at 21:28
3
Solved
Why are those C++11 new functions of header <string> (stod, stof, stoull) not member functions of the string class ?
Isn't more C++ compliant to write mystring.stod(...) rather than stod(mys...
Automata asked 29/1, 2014 at 9:28
3
What is the advantage of having a free function (in anonymous namespace and accessible only in a single source file) and sending all variables as parameters as opposed to having a private class mem...
Easiness asked 9/1, 2014 at 18:55
1
Solved
I am writing my own array class as an exercise. Since, I read non-member functions are actually better in some ways than member functions.
(Scott Meyers)
I am trying to write as many operator ove...
Forayer asked 13/9, 2013 at 15:3
2
Solved
I have a Matrix class and it has overloaded * operators for scalar and matrix multiplications.
template <class T> class Matrix
{
public:
// ...
Matrix operator*(T scalar) const;
// ...
}...
Daffi asked 23/1, 2013 at 14:45
3
Solved
Both Class and Namespace?
This question is about a pattern that I am seeing myself use more and more: Having both a class and a namespace for related concepts. I think this is motivated main...
Lovellalovelock asked 19/1, 2013 at 21:15
4
Solved
I've got a project that I'm using Doxygen to generate documentation for. The documentation of the classes is fine, but I've also got some non-member functions that I use to create objects etc...
Nannette asked 8/5, 2010 at 12:33
1
Solved
I had working on a class and started writing everything in the same .cpp file. However, after a while I could see the class getting bigger and bigger so I decided to split it into a .h and a .cpp f...
Sternlight asked 28/1, 2012 at 18:24
3
Solved
Every time I have some functionality which is in the direction of "utility", I end up wondering which option is the best. For instance, printing message structs (own or external), some encoding/dec...
Disgruntle asked 5/8, 2011 at 8:6
1
Solved
Are the non-member function templates begin(container) and end(container) part of C++0x? If so, in which header file do they live?
Transudation asked 30/7, 2011 at 10:28
3
Solved
I have a set of polymorphic classes, such as:
class Apple {};
class Red : public Apple {};
class Green : public Apple {};
And free functions which compare them:
bool operator==(const Apple&...
Kristie asked 6/6, 2011 at 19:51
7
Solved
While puzzling with some facts on class design, specifically whether the functions should be members or not, I looked into Effective c++ and found Item 23, namely, Prefer non-member non-friend func...
Tymothy asked 13/5, 2011 at 9:14
3
Solved
I have a class template Foo<T>.
I'd like to implement a non-member function Bar that takes two Foos and returns a Foo. I want Bar to be a non-member because it will be more natural for calle...
Muckrake asked 14/3, 2011 at 19:34
5
Solved
After reading sbi and Eli Bendersky's answers in this question, I've started to wondering what static member functions are for.
Shouldn't a class' friend free function be able to do anything ...
Avert asked 18/1, 2011 at 10:45
2
Solved
I read that an overloaded operator declared as member function is asymmetric because it can have only one parameter and the other parameter passed automatically is the this pointer. So no sta...
Ambroid asked 7/1, 2011 at 3:43
2
Solved
I'm trying something like this:
Foo & operator=(Foo & to, const Bar &from);
But I'm getting this error:
E2239 'operator =(Foo &, const Bar &)' must be a member function
A...
Panties asked 21/6, 2010 at 20:57
1 Next >
© 2022 - 2024 — McMap. All rights reserved.