FAQ Database Discussion Community


What happens when a member function with no arguments is called by an object in c++

c++,member-functions,this-pointer
Suppose we have a member function of class X and it is X f() which returns an object of class X and takes no arguments. So if it is called by an object of class X, say X obj is the object. So if we call obj.f(), so as per...

Initialize a const vector in a class constructor (C++)

c++,class,vector,const,member-functions
I am trying to figure out how to initialize a const class member variable, (in this case a vector), to some arbitrary values in the class's constructor. Basically, in the class definition, I have: const vector < pair <float, float> > myVector; In the class's constructor however, I would like...

C++ Callback Function to Member Function

c++,function,callback,member-function-pointers,member-functions
I have never worked with callbacks, but the following code should work according to my professor's notes. It doesn't like the template and has errors about "gauss cannot appear in a constant-expression." Note: GaussElim is a function object (gauss(mx, vector) works in previous code). The DirichletSolver templated callback function: template...

Passing a C++ Member Function Pointer to an STL Algorithm

c++,stl,member-functions,stl-algorithm
I have a member function as follows: class XYZ{ public: float function(float x); private: float m_DensityMin; float m_DensityMax; }; Now, I'm trying to transform a std::vector<float> foo using the std::transform STL algorithm by passing the member function function, and storing the resulting values in a vector bar. If I use...

Correct function signature template for member function

c++,templates,variadic-templates,member-functions
Following up on a question I recently asked, there might be some unnecessary stuff in there but the example is small, what I want to do (and of course if you can think of other cool ways to do this, please share your thoughts), is to allow the user to...

Compile time deduction of template member function

templates,c++11,member-functions
Is it possible to get the return type of a template member function at compile time? I guess I need something along the lines of: template<class T> struct SomeClass { // T must have a function foo(int), but do not know the // return type, it could be anything using...

Defining unnamed class member functions?

c++,class,definition,member-functions
I currently have two unnamed classes defined in my Foo.h: class Foo { public: Foo(); class { private: int x; int y; public: int GetX() { return x; } int GetY() { return y; } } Sub1; class { private: int x; public: int GetX() { return x; } }...

C++: Store pointer to a member function of an object in another object

c++,templates,function-pointers,member-functions
I have a class which shall invoke a function specified by the user on certain occasions. Therefore the class has a method void setExternalPostPaintFunction(void(*function)(QPainter&)); that can be used to "register" a function. This function then will be called on that occasion: class A { public: void setExternalPostPaintFunction(void(*function)(QPainter&)); private: void (*_externalPostPaint)(QPainter&);...

C++, template or pointer to member function

c++,templates,boost,member-functions
I have a series of member functions that are all very similar, and I think I might be able to make my code more maintainable with a template or some other approach, but I am not sure how to do it. Here is an example of one of my functions:...

Private member variable is null when passed from constructor to member function

c++,class,oop,member-functions
I'm pretty new to OOP in c++ so bear with me here. In my header that defines my member variables; class AntibodyJunction { private: //raw seq seqan::Dna5 _raw_sequence; //private funcs void _setVGeneQueryStartTranslation(); public: //V D and J constructor AntibodyJunction(AlignAntibody &, AlignAntibody &, AlignAntibody &, seqan::Dna5 &); ~AntibodyJunction() {}; }; and...