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.

553 questions
-1
votes
1 answer

by overloading [], how to assign values to the second array member in a class?

I am a learner. I am working on operator overloading. I am writing a code that has the below items: 1. A class with two member arrays 2. Overloaded [] function If my class has just one array member, I can overloaded [] to assign the values. But what…
-1
votes
1 answer

Const operator in member function (Why can be in two different parts)?

We can find: 1) const char *get() { return str; } 2) int get() const { return A; } What is the differences of "const" in this two different parts of the function?
Pablo De Luca
  • 673
  • 1
  • 11
  • 22
-1
votes
3 answers

Is it safe to assign reference variable,which is of method level to Class level reference variable?

If i have following code for a Java program class Dotcom{ private int positions[];// position is reference variable at class level //some other instance variables // suppose here we have setter for initialising "positions" public…
OldSchool
  • 1,973
  • 4
  • 18
  • 39
-1
votes
1 answer

It there a need to declare const instance of a class with all attributes const?

This is a followup to Does a class with all attributes const need to have member function declared const as well?. So I've a class PermutationGroup whose all attribute are const. The compiler still make the distinction between const and non-const…
hivert
  • 10,116
  • 3
  • 27
  • 51
-1
votes
6 answers

What is a member function in c++?, does it contain a body?, is it defined in the .h or .cpp file?

I'm new in c++. I'm required to define member functions. I am more familiar with java. I actually confused by the term "member function". Do we have to define it in the header .h file or the .cpp file?
MswatiLomnyama
  • 966
  • 1
  • 10
  • 16
-1
votes
2 answers

How do I use this member, declared in a header, as a function?

These are some parts of my crawler header file. I cannot make changes to this header file. private: int top_position; // The maximum position of the throttle bool left_reverse; // true if left direction is reverse bool…
-1
votes
2 answers

Oracle ORA-01422: exact fetch returns more than requested number of rows

I am trying to create a member function that returns the member names of expired members. My select query works outside of the member function and this member function compiles with no problems but when I call the function I get this…
-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…
-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
  • 607
  • 2
  • 11
  • 31
-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
  • 916
  • 1
  • 6
  • 20
-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…
-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
  • 3
  • 3
-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
1 2 3
36
37