Questions tagged [non-member-functions]
98 questions
0
votes
1 answer
C++Linked list non-member function to reverse print
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)) function how do you print reverse in an iterative…

ghf
- 1
- 1
0
votes
0 answers
In c++ how do i refer a member function of a class to a non member function which is further being called by another member function of that class?
In c++ how do i refer a member function of a class to a non member function which is further being called by another member function of that class?
This is my code and it return into this error:
[Error] cannot convert 'void (example::*)()' to 'void…

Tariqul
- 1
- 2
0
votes
2 answers
C++ "Invalid use of 'this' in non-member function",
Below are the .cpp versions of my character class and its subclasses. I am trying to get the attack() function to work. I made some changes and the current error deals with "invalid use of ‘this’ in non-member function" in the adjustHP() function.…

lucky_batra
- 13
- 7
0
votes
1 answer
Accessing non-member functions from another file
I am wondering if it is possible to access non-member functions from another file. That is, a function declared and defined in a .cpp rather than in its header.
I have made a short example to show what I am asking about:
I have a very basic header…

bmb
- 361
- 2
- 13
0
votes
2 answers
Excluding member functions and inheritance, what are some of the most common programming patterns for adding functionality to a class?
There're likely no more than 2-4 widely used approaches to this problem.
I have a situation in which there's a common class I use all over the place, and (on occasion) I'd like to give it special abilities. For arguments sake, let's say that type…

Seph Reed
- 8,797
- 11
- 60
- 125
0
votes
1 answer
How to call a non-member function that takes in an object within a method
Say I have a class Student, and I have already declared a non-member function called "function_A" that takes in as an argument, type Student.
Now say INSIDE the Student class, I had a member function, and in it, I wanted to reference the non-member…

google11video
- 63
- 6
0
votes
2 answers
why can we access a non_member function from member function in c++
The following code compiles without any warning or error:
#include
using namespace std;
class demo_class
{
int x;
float y;
public:
void fun(void);
};
void fun2(void)
{
cout<<"i am fun2\n";
}
void…

play store
- 393
- 1
- 5
0
votes
1 answer
Specify that a non-member function should be called instead of member function
I have a class with a member called f and simultaneously a generic free function called f.
The free function f is meant to called from another member (called g below).
class A{};
int f(A const& a){return 5;} // generic free f
template

alfC
- 14,261
- 4
- 67
- 118
0
votes
3 answers
C++ static non-member function returning object of a template class
I have a static non-member function which returns a template class object depending on the type of the object.
template< typename T >
class Example
{
....
};
static Example non_member_function(int var) {
if (var == 1)
return…

user3566905
- 113
- 1
- 6
0
votes
3 answers
In which file do we put non-member function in C++?
What is the normal practice when it comes to non-member function in C++? Do we put them in main.cpp or header file or class implementation file, or do we make a separate .cpp file for it?
If the normal practice is to make a separate file, then…

juice009
- 3
- 1
- 5
0
votes
1 answer
CakePHP 3 - call object from other helper
I'm actually working on a Helper for CakePHP3 that include BsHelper and then the BsFormHelper.
Actually everything looks good, no problem with Bootstrap formats.
I try now to create a ckEditor instance, but I meet some several problems.
If i try to…

Lucien Leroux
- 5
- 2
0
votes
2 answers
Name, Papers , Books was not declared in this scope non-member function C++
I have an error when I declare the non-member function listOverview();
void listOverview()
{
std::cout << "Overview of books of " << name << std::endl;
for (auto p : books)
{
std::cout << p.toString() << std::endl;
}
std::cout…

Noel Peña Blanco
- 21
- 1
- 9
0
votes
5 answers
Class scope and private members?
I am defining a function to add elements to the vector original_points, named void add_point(). Why is highlighting original_points as undefined, in the function body, when I am using type qualifier: friend (to gain access) and it is in the…

Ziezi
- 6,375
- 3
- 39
- 49
0
votes
1 answer
Correct way to implement operator!= for templates outside of class as a free function
I have a following template with inner classes in a map.hpp file:
template
class Map {
// public members of Map ...
class Iterator {
//public members of Iterator ...
friend bool…

shiraz
- 1,208
- 2
- 12
- 26
0
votes
3 answers
c++ create, assign and compare a new variable to two object inside an Operator Overloaded function.
The assignment:
Implement an Alien class using a provided Alien.h file. An alien, in this scenario is described in terms of his/her height, weight, and gender. To compare two aliens, you use the following equation to determine the alien’s…

C Morgan
- 3
- 1
- 6