Questions tagged [non-member-functions]

86 questions
1
vote
2 answers

How to determine local static variable in non-member function using dwarf

Im trying to use dwarf to compare two c++ files, but I am running into issues when I get to local variables in non-member functions. Consider the following code - int f(){ [static] int j=0; return j; } If I compile it without the static…
0
votes
1 answer

Sorting by different data members of a class C++

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 records. Now the sorting can be done on the basis of…
rKA
  • 3
  • 1
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.…
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
  • 321
  • 1
  • 7
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
  • 4,704
  • 7
  • 30
  • 65
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…
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
  • 383
  • 1
  • 5
0
votes
2 answers

How to define an inline free function (non member function) in C++?

In C++, I need to define some inline general functions. However, when I write the prototype in a header file and the implementation in a.cpp file, I encounter with "LNK2001 unresolved external symbol" error. Shall I remove the .cpp file and…
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
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
  • 103
  • 1
  • 5
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
  • 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…
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…