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
-3
votes
1 answer

calling non-const function on non-const member in const function

The member is non const, and the member's member function is non const, when it is called on a const member function, it will generate an error, complains about: error: passing 'const foo' as 'this' argument discards qualifiers…
fluter
  • 13,238
  • 8
  • 62
  • 100
-3
votes
1 answer

Use Member functions of array which contains struct

I made an array wit a struct for example: #include #include "utils/Configuration.h" #include using namespace std; using namespace cv; struct plausibilitylinestruct{ int x0; int y0; int x1; …
Maksymal
  • 3
  • 2
-3
votes
1 answer

Add class member dynamically inside another member

I'm pretty new to C++ and I am just experimenting it so I was looking through an exercise book on C++ and I found an interesting problem where you have to use classes. I figured out a solution to it but my solution is writen like I would write it in…
Alfi Louis
  • 105
  • 1
  • 2
  • 5
-3
votes
1 answer

The difference between index and an iterator is?

Is it true that index is a member function that can return the value of an element in a container and an iterator is a value that can access, move through and move through a container?
Dog
  • 33
  • 2
-3
votes
2 answers

Call member function on object pointer

I am trying to write a simple game in C++ and currently have my Game_Window class holding an array of pointers to game objects as follows: class Game_Window { private: int width; int height; int num_objects; public: char**…
-3
votes
1 answer

Member function accessible in main function, but in while loop throws error "not declared in this scope"

I'm trying to make a simple looping menu. I moved the member function mainMenu() above the main() class as the internet suggested But when I try to call mainMenu() from inside a while loop, the compiler gives the following error, as noted in the…
-3
votes
1 answer

Why is the const version of a member function always selected even the non-const version exists?

Update: This is a wrong question. There is no non-const version of string::data(); ignore this question. I'm sorry! string::data has a const version and a non-const version. In my following code, str is obviously a non-const object, so str.data()…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
-4
votes
2 answers

How to solve "return a value" Error in a class member function?

//PROGRAM: #include #include using namespace std; class complex { private: double re, img; public: complex(); void input(); complex SubCom(complex c1, complex c2); complex SumCom(complex c1, complex c2); …
-4
votes
1 answer

Pointer to Class Member functions

I want to store class member function address, to local data structure(table) typedef struct { unsigned int id; void (TCLASS::*proc)(); } TSTRUCT; class TCLASS{ public: void tfunct(); const TSTRUCT t1 = { 1, &tfunct}; };
sonaj70
  • 1
  • 1
-7
votes
1 answer

What step can I take to fix the error of “Unknown type name 'Node' ”?

I am running the following program. In this program I have to implement a doubly linked list. And I am still to complete this program. Howvever, look below at the program I have so far. I am getting an error "Unknown type name 'Node'" in the…
-7
votes
2 answers

Variable life-time in member-function, values keep reseting to `0`, why?

PROBLEM DESCRIPTION I am trying to write an implementation of the beetle game for kids. The following code is initializing wings, legs, head, etc, to zero whenever I call the function. Where should the initialization be so that I can increment…
1 2 3
41
42