member

Generic Class Members in C#?

允我心安 提交于 2019-12-06 02:23:36
问题 Hey, I think I have the wrong idea here, but I'm not sure what is best. I want a class with a member variable that can be of any type, depending on what is needed at the time. So far, I have something like this: public class ConfigSetting<T> { private T value; public T GetValue() { return value; } public void ChangeValue() { } public ConfigSetting(string heading, string key) { this.value = DerivedMethods.configsettings.SettingGroups[heading].Settings[key].RawValue; } } The type returned by

How do I get a list of all the public variables I have in a Class? (C#)

六月ゝ 毕业季﹏ 提交于 2019-12-05 22:56:26
I have a class that has A LOT of public variables and I need to be able to get a list of them. Here's an example of my class: public class FeatList: MonoBehaviour { public static Feat Acrobatic = new Feat("Acrobatic", false, ""); public static Feat AgileManeuvers = new Feat("Agile Maneuvers", false, "" ); void Start(){}} Except there are about 100 more variables. Is there any possible way to get all these member variables in one manageable array? Or have I screwed myself over? If by "Variables" you mean class fields (like variables at the class level) you can use reflection to get access, like

Inheritance of class members, mixed with templates

坚强是说给别人听的谎言 提交于 2019-12-05 20:58:30
in the code below, why does T2 give this error ‘m_t’ was not declared in this scope , while TB is fine ? And how can I have access to T1's members in T2 while still using templates ? // All good class TA { public: TA() {} protected: int m_t; }; class TB : public TA { public: TB() {} int get() { return m_t; } protected: }; // Error in T2 template<typename T> class T1 { public: T1() {} protected: int m_t; }; template<typename T> class T2 : public T1<T> { public: T2() {} int get() { return m_t; } protected: }; You need to use this->m_t to make it a dependent name. When templates are compiled,

C++ stream as a member variable

妖精的绣舞 提交于 2019-12-05 20:35:49
问题 I've got a C++ class which I would like to hold a stream used for logging. The stream should be able to be set (and possibly reset) after the construction of the object. It should be possible to set the stream as std::cout , or as a file stream to log to a file, or as a stringstream which does nothing more than ignore the data (a /dev/null of sorts). In any case, it should be an ostream type object, which the creator of the object can reset at any time. The class itself is oblivious to the

How does function overloading work at run-time, and why overload?

家住魔仙堡 提交于 2019-12-05 12:10:17
Let's say I have a class named ClothingStore. That class has 3 member functions, that point a visitor to the right department of the store. Member functions are ChildrenDept, MenDept and WomenDept, depending on whether the visitor is a child, a man or a woman. Function overloading can be used to make 3 functions that have same name, say, PointToDept, but take different input argument ( child, man, woman ). What is actually happening on run-time when program is executing ? My guess is that compiler adds switch statements to the program, to select the right member function. But that makes me

Member function definition

旧巷老猫 提交于 2019-12-05 08:16:53
What is the right approach to take: Define the member (class) function inside the class? Define the member (class) function outside the class? Thanks. Assuming you're talking about these three possibilities: Method defined in class definition in header file. Method define outside class definition in header file. Method define outside class definition in implementation file. Then project and company guidelines may force you to use (1) or (3) always. When you have a choice, it's IMHO best to adapt to circumstances at hand, considering things such as Do you want a header-only module? Then (1) as

Fatal error: Call to a member function getKeyName()

天大地大妈咪最大 提交于 2019-12-05 03:23:36
I am new in joomla . i have created a joomla component and when i click on new button in admin then i am getting such error. Fatal error: Call to a member function getKeyName() on a non-object in C:\xampp\htdocs\Joomla1\libraries\joomla\application\component\modeladmin.php on line 801 Please help The problem is cause by your JTable class. Make sure you have correct filename and class name in administrator/components/com_YOUREXTENSION/tables/ You can find example in any core Joomla extension. public function getTable($type = 'Category', $prefix = 'CatalogTable', $config = array()) { return

How to call the __invoke method of a member variable inside a class

断了今生、忘了曾经 提交于 2019-12-05 01:47:28
PHP 5.4.5, here. I'm trying to invoke an object which is stored as a member of some other object. Like this (very roughly) class A { function __invoke () { ... } } class B { private a = new A(); ... $this->a(); <-- runtime error here } This produces a runtime error, of course, because there's no method called a. But if I write the call like this: ($this->a)(); then I get a syntax error. Of course, I can write $this->a->__invoke(); but that seems intolerably ugly, and rather undermines the point of functors. I was just wondering if there is a better (or official) way. There's three ways:

To inline or not to inline

耗尽温柔 提交于 2019-12-05 01:27:33
I've been writing a few classes lately; and I was wondering whether it's bad practice, bad for performance, breaks encapsulation or whether there's anything else inherently bad with actually defining some of the smaller member functions inside a header (I did try Google!). Here's an example I have of a header I've written with a lot of this: class Scheduler { public: typedef std::list<BSubsystem*> SubsystemList; // Make sure the pointer to entityManager is zero on init // so that we can check if one has been attached in Tick() Scheduler() : entityManager(0) { } // Attaches a manager to the