member

How do you pass a member function pointer?

I am trying to pass a member function within a class to a function that takes a member function class pointer. The problem I am having is that I am not sure how to properly do this within the class using the this pointer. Does anyone have suggestions? Here is a copy of the class that is passing the member function: class testMenu : p...

Function pointer to template class member functions

I have a templated class defined (in part) as template <class T> MyClass { public: void DoSomething(){} }; If I want to call DoSomething from another class, but be able to do this for multiple 'T' types in the same place, I am stuck for an idea as method functions pointers are uniquely constrained to the class type. Of course, each...

Static nested class in Java, why?

Hi All, I was looking at the Java code for LinkedList and noticed that it made use of a static nested class Entry. public class LinkedList<E> ... { ... private static class Entry<E> { ... } } What is the reason for using a static nested class, rather than an normal inner class? The only reason I could think of, was so that Entry ...

c# using setters or getters from base class

Is it recommended to set member variables of a base class to protected, so that subclasses can access these variables? Or is it more recommended to set the member variables to private and let the subclasses get or set the varible by getters and setters? And if it is recommended to use the getters and setters method, when are protected v...

Why doesn't C++ have a pointer to member function type ?

I could be totally wrong here, but as I understand it, C++ doesn't really have a native "pointer to member function" type. I know you can do tricks with Boost and mem_fun etc. But why did the designers of C++ decide not to have a 64-bit pointer containing a pointer to the function and a pointer to the object, for example? What I mean s...

C++ member variable aliases?

I'm pretty sure this is possible, because I'm pretty sure I've seen it done. I think it is awesome, but I will gladly accept answers along the lines of "this is a terrible idea because ____". Say we have a basic struct. struct vertex { float x, y, z; }; Now, I want to implement aliases on these variables. vertex pos; vertex col;...

Accessors vs. public members

I have a class with a lot of built-in type members with read/write access. Should I make them public members and provide get/set methods for each one? How about structures? ...

Is it possible to access private members of a class?

Is it possible to access private members of a class in c++. provided you don't have a friend function and You don't have access to the class definition ...

How to deal with ThreadPool and member variables?

Hello everyone, I am a bit new to ThreadPool in .NET. I was wondering, if I can only send one object to my callback method, how am I able to access the class member variable to call its methods? (see customClass in CallBack()) And how would I load the data from customClass? Do I pass the customClass to a different CallBack method? i...

getter and setter for class in class c#

Hello. I a little problem. Assuming we have a class InnerClass with attributes and getter/setter. We also have a class OuterClass containing the InnerClass. e.g. class InnerClass { private int m_a; private int m_b; public int M_A { get { return m_a; } set { ...

Does an overloaded __get need to manage all member variables?

I am creating a __get() function for a class to control access to my private member variables. Do I need to design the function to handle all possible member value reads or can I not write it for members that are public? Also, I am assuming that classes that inherit this class will use my __get() function to access private members. cl...

C++: syntax for accessing member struct from pointer to class

I'm trying to access a member structs variables, but I can't seem to get the syntax right. The two compile errors pr. access are: error C2274: 'function-style cast' : illegal as right side of '.' operator error C2228: left of '.otherdata' must have class/struct/union I have tried various changes, but none successful. #include <iostream...

Where can I find, or how can I create an elegant C++ member function template wrapper mechanism without resporting to boost?

I want to be able to templatize a class on a member function without needing to repeat the arguments of the member function -- i e, derive them automatically. I know how to do this if I name the class based on how many arguments the function takes, but I want to derive that as well. Something like this, although this doesn't work (at le...

Nullable variable types - .value member

Hello, I was wondering - when would I want to use the .Value member on a nullable type instead of just calling the variable itself? e.g.. bool? b = true; why would i use b.Value to get the value instead of just using b? What advantage or function does the .Value call add? ...

what is a member vs. a property

A friend who is new to OO programming asked me the difference between a Member and Property, and I was ashamed to admit that I couldn't give him a good answer. Since properties can also be objects themselves, I was left with a general description and list of exceptions. Can somebody please lay out a good definition of when to consider s...

default visibility of C++ class/struct members

In C++, why is private the default visibility for members of classes, but public for structs? ...

_beginthreadex static member function

How do I create a thread routine of a static member function class Blah { static void WINAPI Start(); }; // .. // ... // .... hThread = (HANDLE)_beginthreadex(NULL, 0, CBlah::Start, NULL, NULL, NULL); This gives me the following error: ***error C2664: '_beginthreadex' : cannot convert parameter 3 from 'void (void)' to 'unsigne...

Unit testing functions that only change private member variables?

I am currently writing unit tests for a ViewModel in my project that uses Prism and the MVVM pattern. My view mainly consists of an ItemsControl that reacts to different mouse events (LeftMouseButtonDown, LeftMouseButtonUp etc.). When such a mouse event happens the EventArgs and some other glue info is handed to the ViewModel and an app...

Lua scripting implementation

Hello, I'm currently working on implementing Lua into one of the applications that I'm working on. Currently I'm just using the C api and registering functions using lua_register, but I'd like to be able to pass static and non static function pointers to certain class methods. I've found certain libraries on the net, but since I need...

F# : Accessing public readonly members of structs in external assemblies

I'm getting a strange error when I use F# to read a public readonly member of a struct type defined in a C# assembly. // C#: compile to Lib.dll namespace Lib { public class MyClass { public readonly int ReadonlyFoo; } public struct MyStruct { public readonly int ReadonlyFoo; public int WriteableFoo; } } ...