What are the benefits of free functions in an unnamed namespace over a class with private member functions?

see this question: Effective C++ Item 23 Prefer non-member non-friend functions to member functions and also C++ Member Functions vs Free Functions You should prefer free functions, in the extent that it promotes loose coupling. Consider making it a member function only if it works on the guts of your class, and that you consider … Read more

Should I prefer private member functions, or functions in an unnamed namespace? [duplicate]

In the semi large projects where I usually work (more than 2 million lines of code) I would ban private class functions if I could. The reason being that a private class function is private but yet it’s visible in the header file. This means if I change the signature (or the comment) in anyway … Read more

error: passing const xxx as ‘this’ argument of member function discards qualifiers

The objects in the std::set are stored as const StudentT. So when you try to call getId() with the const object the compiler detects a problem, mainly you’re calling a non-const member function on const object which is not allowed because non-const member functions make NO PROMISE not to modify the object; so the compiler … Read more

Why is a call to a shadowing non-virtual member function in the derived class not calling the base class member function?

Yep, you are misunderstanding a little. The method of the same name on the derived class will hide the parent method in this case. You would imagine that if this weren’t the case, trying to create a method with the same name as a base class non-virtual method should throw an error. It is allowed … Read more

How can I create a pointer to a member function and call it?

Read this for detail : // 1 define a function pointer and initialize to NULL int (TMyClass::*pt2ConstMember)(float, char, char) const = NULL; // C++ class TMyClass { public: int DoIt(float a, char b, char c){ cout << “TMyClass::DoIt”<< endl; return a+b+c;}; int DoMore(float a, char b, char c) const { cout << “TMyClass::DoMore” << endl; … Read more

How to separate a class and its member functions into header and source files

The class declaration goes into the header file. It is important that you add the #ifndef include guards. Most compilers now also support #pragma once. Also I have omitted the private, by default C++ class members are private. // A2DD.h #ifndef A2DD_H #define A2DD_H class A2DD { int gx; int gy; public: A2DD(int x,int y); … Read more

Why is a call to a virtual member function in the constructor a non-virtual call?

Calling virtual functions from a constructor or destructor is dangerous and should be avoided whenever possible. All C++ implementations should call the version of the function defined at the level of the hierarchy in the current constructor and no further. The C++ FAQ Lite covers this in section 23.7 in pretty good detail. I suggest … Read more

std::mem_fun vs std::mem_fn

std::mem_fun is deprecated. std::mem_fn can do everything it does, and it does it more conveniently. The relation between the two is the same as the relation between std::bind1st/std::bind2nd and the C++11 std::bind. Both std::mem_fn and std::bind were developed and mastered after std::bind1st and std::mem_fun were made into the C++98 Standard. So that means we had … Read more

techhipbettruvabetnorabahisbahis forumuedusedueduedueduedusedueduseduedus