member-functions

using and overloading a template member function of a base class?

邮差的信 提交于 2019-12-08 22:10:17
问题 In the following, struct Y overloads X 's member function f . Both overloads are template functions, but take different arguments ( typename and int ), to be explicitly specified: struct X { template <typename> static bool f() { return true; } }; struct Y : public X { using X::f; template <int> static bool f() { return false; } }; int main() { std::cout << Y::f <void>() << " " << Y::f <0>() << std::endl; } This prints 1 0 using gcc, as expected. However, clang (3.3) complains that [...] error

C++0x | Why std::atomic overloads each method with the volatile-qualifier?

不问归期 提交于 2019-12-08 19:28:55
问题 The following excerpt from the current draft shows what I mean: namespace std { typedef struct atomic_bool { bool is_lock_free() const volatile; bool is_lock_free() const; void store(bool, memory_order = memory_order_seq_cst) volatile; void store(bool, memory_order = memory_order_seq_cst); bool load(memory_order = memory_order_seq_cst) const volatile; bool load(memory_order = memory_order_seq_cst) const; operator bool() const volatile; operator bool() const; bool exchange(bool, memory_order =

Are preconditions and postconditions needed in addition to invariants in member functions if doing design by contract?

好久不见. 提交于 2019-12-07 09:34:05
问题 I understand that in the DbC method, preconditions and postconditions are attached to a function. What I'm wondering is if that applies to member functions as well. For instance, assuming I use invariants at the beginning at end of each public function, a member function will look like this: edit: (cleaned up my example) void Charcoal::LightOnFire() { invariant(); in_LightOnFire(); StartBurning(); m_Status = STATUS_BURNING; m_Color = 0xCCCCCC; return; // last return in body out_LightOnFire();

C++ class member function and callback from C API

做~自己de王妃 提交于 2019-12-07 08:19:08
问题 I am trying to learn how to call this write_data(…) function from the funmain() function in the class as shown in the code bellow. (I know this program works if I just list these two functions without putting it inside a class). curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data) line gives me error and wouldn’t let me call the write_data(…) function. Can you please correct my code and tell me how I can achieve this. Any help would be greatly appreciated. Thanks. error C3867: 'go

get the real address(or index in vTable) of virtual member function

这一生的挚爱 提交于 2019-12-07 01:46:51
问题 In c++ is there any way to get the real address of member function, or the index in vTable ? Updated: I don't know the INDEX in vTable and I don't know the address Here's why I want to know this: I want to hook the function ID3DXFont->DrawText of DirectX. If I know the index of the DrawText in the vTable, I can replace it to do the hook. But how to get the index? If it's able to get the the real address, I can search it in the vTable to get the index. And not particularly ID3DXFont->DrawText

static var in member function

北城以北 提交于 2019-12-06 02:15:29
问题 bool SomeClass::Function( bool thankYou = true ) { static bool justAbool = false; // Do something with justAbool; ... } I have searched around but I can't find anything about this except globals vars or member functions itself. What does the above do, i.e. what happens, does justAbool keep its value after leaving the scope? Or does it 'remember' the value when it re-enters the scope? 回答1: static when applied to a local variable gives that variable static storage duration . This means that the

Pointer to member function syntax

大兔子大兔子 提交于 2019-12-05 23:27:32
I'm trying to wrap my head around pointers to member functions and am stuck with this example: #include <iostream> class TestClass { public: void TestMethod(int, int) const; }; void TestClass::TestMethod(int x, int y) const { std::cout << x << " + " << y << " = " << x + y << std::endl; } int main() { void (TestClass::*func)(int, int) const; func = TestClass::TestMethod; TestClass tc; tc.func(10, 20); return 0; } What I think the code should do: In the first line of main I declare a pointer to a member function of class TestClass , which returns nothing/takes two int 's and is declared const ,

Are preconditions and postconditions needed in addition to invariants in member functions if doing design by contract?

落爺英雄遲暮 提交于 2019-12-05 15:55:13
I understand that in the DbC method, preconditions and postconditions are attached to a function. What I'm wondering is if that applies to member functions as well. For instance, assuming I use invariants at the beginning at end of each public function, a member function will look like this: edit: (cleaned up my example) void Charcoal::LightOnFire() { invariant(); in_LightOnFire(); StartBurning(); m_Status = STATUS_BURNING; m_Color = 0xCCCCCC; return; // last return in body out_LightOnFire(); invariant(); } inline void Charcoal::in_LightOnFire() { #ifndef _RELEASE_ assert (m_Status == STATUS

C++ class member function and callback from C API

我只是一个虾纸丫 提交于 2019-12-05 14:19:40
I am trying to learn how to call this write_data(…) function from the funmain() function in the class as shown in the code bellow. (I know this program works if I just list these two functions without putting it inside a class). curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data) line gives me error and wouldn’t let me call the write_data(…) function. Can you please correct my code and tell me how I can achieve this. Any help would be greatly appreciated. Thanks. error C3867: 'go_website::write_data': function call missing argument list; use '&go_website::write_data' to create a pointer

Function taking both pointer to member-function and pointer to const member-function

一世执手 提交于 2019-12-05 08:21:37
I have the following code base: template <typename Type> class SomeClass { public: template <typename ReturnType, typename... Params> void register_function(const std::pair<std::string, ReturnType (Type::*)(Params...)> fct) { auto f = [fct](Params... params) -> ReturnType { return (Type().*fct.second)(std::ref(params)...); } // ... } }; This works when I pass a pointer to a member-function (non-const). However, if I want to pass a pointer to a const member-function, it results in a compile error and I must duplicate the above function to get this code: template <typename Type> class SomeClass