Questions tagged [member-functions]

A function declared and/or defined within a class.

A member function is a procedure that whose signature is declared inside a class. This function takes an implicit argument of the same type as the containing class and is only accessible via an object of that type. When the function is static, no implicit argument is needed, but the function must be invoked via the class' scope. In contrast, a free-function does not have an implicit argument of the class type nor is invoked via a class scope.

626 questions
-1
votes
1 answer

C++ using getArea() and accessing an array to work out area of circle

I need some help with the following problem which is to work out the areas of each circle within an array using the getArea() method. How do I go about accessing an array and then working out the area of the circle using Circle::getArea() member…
user1582575
  • 89
  • 3
  • 4
  • 12
-2
votes
1 answer

C++ - Modify member function if argument (function) is given

I am creating a class which takes as input arguments either 1 or 2 functions. My goal is that if only one function func is given then the member function dfunc is calculated using num_dfunc (which is the numerical derivative of func and is hardcoded…
João Viana
  • 31
  • 1
  • 5
-2
votes
2 answers

Call To A Member Function On String

Hello Guys I Have This Function In My Model public function photo () { return $this -> photo; } And I Called The Function From My Blade {{$model = \App\Models\mainCategory::class}}
user19630919
-2
votes
1 answer

Class's container get() member function usage vs copying

I have created a config class which loads configuration from a config YAML. I have created vector containers for each type // Pseudo Code class config { private: std::vector c_name; public: config(yaml_file_path) { …
ABHINAV RANA
  • 67
  • 1
  • 10
-2
votes
2 answers

Member function mapping in python

I have a class with many member functions, and I want self.func to have function pointer based on provided name. However, this way each class should have a dict from all names to functions which is clearly a waste. Is there a better way to do it?…
Roy
  • 65
  • 2
  • 15
  • 40
-2
votes
3 answers

How to overload getter functions without adding/ removing `const`ness of mem function?

I could not figure this out, why C++ is not allowing overloading according to the return type as in the following case the three member(getter) function has different function signature and even when to store the pointer to the member function we…
Const
  • 1,306
  • 1
  • 10
  • 26
-2
votes
2 answers

Can I make a C++ method in external assembly (function.asm)?

I am writing a program that requires one function in assembly. It would be pretty helpful to encapsulate the assembly function in a C++ class, so its own data is isolated and I can create multiple instances. If I create a class and call an external…
kanito73
  • 87
  • 4
-2
votes
1 answer

error: invalid use of non-static member function

Issue: I am trying to instantiate a class (say class A) inside another class (say class B) and then call all the member functions of class A inside the class B for the instantiated object. I get the following error message for every call of class A…
Arun Kumar
  • 634
  • 2
  • 12
  • 26
-2
votes
2 answers

What is the way of permanently changing class variables from inside the member function?

print("Hello World") class testing: params = 1 print(params) #@classmethod def __init__(self, params): self.params = params print(params) b = testing(params = 5) Output: Hello World 1 1 How do I get changed values of params using…
runaway57
  • 5
  • 4
-2
votes
1 answer

Cannot access class member of a 2d array of object pointers (type***)

I am making conway's game of life. I have two classes, one for the plane of cells, and another for the cells. The cells are like a 2d linked list with 4 pointers per cell pointing to the vertical and horizontal neighbors. When trying to access any…
Anandamide
  • 243
  • 1
  • 15
-2
votes
2 answers

When/if to make a non-virtual function a member function

I am trying to get a feel for modern C++ idioms and best practices, and I wanted to ask if, when authoring a class, there was ever a time one should make a function a member function, instead of a free-function in the class's namespace, besides when…
-2
votes
2 answers

Overriding virtual member function containing constant

How can I override a virtual member function of the following type: virtual AnimalId func(int index) const where AnimalId is a typedef unsigned int I tried several ways but either ending up by an error that I don't give output or that I don't have…
CryoPeep
  • 3
  • 2
-2
votes
2 answers

User input in main accessed by member functions

I have this code: #include #include #include "header8.h" using namespace std; int main() { Counter test; string input; cout << "Enter a string\n"; getline(cin, input); test.countcharacters(); …
PhDre
  • 65
  • 1
  • 2
  • 8
-3
votes
1 answer

What does this error mean? C6001: using uninitialized memory 'Rect.'

Visual Studio gave this bizzare error: C6001: using uninitialized memory 'Rect.' #include #include using namespace std; class Rectangle {public: int length, width; int Area(int length, int width) { return…
-3
votes
1 answer

Is there any problem if I hold a member function pointer out of the pointer instance scope

type A struct { x1 []int x2 []string } func (this *A) Test() { fmt.Printf("this is: %p, %+v\n", this, *this) } func main() { var fn func() { a := &A{} a.x1 = []int{1, 2, 3} a.x2 = []string{"one", "two",…
1 2 3
41
42