member-functions

what does “error : a nonstatic member reference must be relative to a specific object” mean?

帅比萌擦擦* 提交于 2019-11-29 23:44:06
int CPMSifDlg::EncodeAndSend(char *firstName, char *lastName, char *roomNumber, char *userId, char *userFirstName, char *userLastName) { ... return 1; } extern "C" { __declspec(dllexport) int start(char *firstName, char *lastName, char *roomNumber, char *userId, char *userFirstName, char *userLastName) { return CPMSifDlg::EncodeAndSend(firstName, lastName, roomNumber, userId, userFirstName, userLastName); } } On line return CPMSifDlg::EncodeAndSend I have an error : Error : a nonstatic member reference must be relative to a specific object. What does it mean? EncodeAndSend is not a static

C++ typedef member function signature syntax

不羁的心 提交于 2019-11-29 22:21:37
I want to declare type definition for a member function signature. Global function typedefs look like this: typedef int (function_signature)(int, int); typedef int (*function_pointer) (int, int); But I'm not able to the same thing for a member function: typedef int (foo::memberf_signature)(int, int); // memberf_pointer is not a member of foo typedef int (foo::*memberf_pointer)(int, int); It sounds logically to me, because "foo::" ist the syntax to access a member in the class foo. How can I typedef just the signature? For questions regarding the awkward function pointer syntax, I personally

Why class member functions shadow free functions with same name?

≡放荡痞女 提交于 2019-11-29 09:51:44
It recently came to my attention that member functions completely shadow free functions with the same name when inside the class. And by completely i mean that every free function with the same name is not considered for overload resolution at all. I can understand why it's done with somwthing like this: void f(); struct S { void f(); void g() { f(); // calls S::f instead of ::f } }; where the functions have identical signatures, its only natural as variable scoping works the same way. But why prohibit unambigious calls where free function has different signature like this: void f(); struct S

How to use variadic templates to make a generic Lua function wrapper?

我与影子孤独终老i 提交于 2019-11-29 09:32:37
问题 For my current project, I've been writing a lot of C/C++ to Lua wrappers. A large number of these are simple setters and getters, so I managed to write some templates that make it easy to generate these, like so: // Class Return Field template <typename T, typename U, U T::*Member> int luaU_get(lua_State* L) { T* obj = luaW_check<T>(L, 1); luaU_push<U>(L, obj->*Member); return 1; } static luaL_reg Foo_Table[] = { ... // Now I can just use this generic template to avoid // writing simple

Does every c++ member function take `this` as an input implicitly?

泪湿孤枕 提交于 2019-11-29 09:07:07
When we create a member function for a class in c++, it has an implicit extra argument that is a pointer to the calling object -- referred as this . Is this true for any function, even if it does not use this pointer. For example, given the class class foo { private: int bar; public: int get_one() { return 1; // Not using `this` } int get_bar() { return this->bar; // Using `this` } } Would both the functions ( get_one and get_bar ) take this as an implicit parameter, even though only one of them actually uses it? It seems like a bit of a waste to do so. Note : I understand the correct thing to

How to list the functions/methods of a javascript object? (Is it even possible?)

℡╲_俬逩灬. 提交于 2019-11-29 06:31:16
This question is intentionally phrased like this question . I don't even know if this is possible, I remember vaguely hearing something about some properties not enumerable in JS. Anyway, to cut a long story short: I'm developing something on a js framework for which I have no documentation and no easy access to the code, and it would greatly help to know what I can do with my objects. I think this is what you are looking for: var obj = { locaMethod: function() { alert("hello"); }, a: "b", c: 2 }; for(var p in obj) { if(typeof obj[p] === "function") { // its a function if you get here } } If

What are the rules for function pointers and member function pointers to Standard functions?

*爱你&永不变心* 提交于 2019-11-29 04:29:00
What are the existing rules for taking function pointers or member function pointers to Standard functions? For example, something like auto p = &std::string::size; Is this legal? Would it be more or less legal if I explicitly requested the correct type, so it would function even if there was an additional implementation-added overload of std::string::size ? Using the "correct" type doesn't make things better: Except for the virtual functions all functions in the standard C++ library can have additional arguments as long as these are defaulted. Since the functions can also be declared with

C++ typedef member function signature syntax

梦想的初衷 提交于 2019-11-28 19:06:02
问题 I want to declare type definition for a member function signature. Global function typedefs look like this: typedef int (function_signature)(int, int); typedef int (*function_pointer) (int, int); But I'm not able to the same thing for a member function: typedef int (foo::memberf_signature)(int, int); // memberf_pointer is not a member of foo typedef int (foo::*memberf_pointer)(int, int); It sounds logically to me, because "foo::" ist the syntax to access a member in the class foo. How can I

error: default argument given for parameter 1

痞子三分冷 提交于 2019-11-28 16:56:05
I'm getting this error message with the code below: class Money { public: Money(float amount, int moneyType); string asString(bool shortVersion=true); private: float amount; int moneyType; }; First I thought that default parameters are not allowed as a first parameter in C++ but it is allowed. Yacoby You are probably redefining the default parameter in the implementation of the function. It should only be defined in the function declaration. //bad (this won't compile) string Money::asString(bool shortVersion=true){ } //good (The default parameter is commented out, but you can remove it totally

How can C++ virtual functions be implemented except vtable? [duplicate]

丶灬走出姿态 提交于 2019-11-28 08:25:50
Possible Duplicate: A question about virtual mechanism in C++ Is using vtable the only way to implement virtual member functions mechanism in C++? What other ways exist? Another known mechanism is type dispatch functions. Effectively, you replace the vtable pointer by a typeid (small enum). The (dyanmic) linker collects all overrides of a given virtual function, and wraps them in one big switch statement on the typeid field. The theoretical justifcation is that this replaces an indirect jump (non-predicatble) by lots of predicatable jumps. With some smarts in choosing enum values, the switch