member-variables

C++: Copy contructor: Use Getters or access member vars directly?

Have a simple container class: public Container { public: Container() {} Container(const Container& cont) //option 1 { SetMyString(cont.GetMyString()); } //OR Container(const Container& cont) //option 2 { m_str1 = cont.m_str1; } public string GetMyString() { return m_str...

Supress unused variable warning in C++ => Compiler bug or code bug?

Presently, I am using the following function template to suppress unused variable warnings: template<typename T> void unused(T const &) { /* Do nothing. */ } However, when porting to cygwin from Linux, I am now getting compiler errors on g++ 3.4.4 (On linux I am 3.4.6, so maybe this is a bug fix?): Write.cpp: In member function `vo...

Is C++ static member variable initialization thread-safe?

Hi! According to following resources, in C++(Specially Visual C++) scoped static variable initialization isn't thread safe. But, global static variables are safe. http://stackoverflow.com/questions/1052168/thread-safe-static-variables-without-mutexing http://blogs.msdn.com/oldnewthing/archive/2004/03/08/85901.aspx So, is following co...

How to implement a read-only member variable in PHP?

When trying to change it,throw an exception. ...

Access reading error when using class member variable

Hi, I have a class with private member variables declared in a header file. In my constructor, I pass in some filenames and create other objects using those names. This works fine. When I try to add another member variable, however, and initialize it in the constructor, I get an access reading violation. I sent the code to someone else ...

Is it possible to get all member variables in flash(AS3)?

Hi, I am trying grab all the member variables in AS3, and then foreach one i would like to process it in various ways. I would need the name and then if it is a collection of some type I would like to loop through that collection as well. I am attempting to essentially serialize in a somewhat custom fashion. Thanks! ...

php classe: problem getting value from function into a member variable

I have a function that gets a value from the database and returns it. I call the function to store it into a member variable but I get the following error: Parse error: parse error, expecting `','' or `';'' in I:\wamp\www\deposit\classes\Site.php on line 14 This is the line that causes the error public static $depositmoney = self::ge...

Can I trick access to private C++ class member variables?

Possible Duplicate: Accessing private members Is it possible to access private members of a class? Is there a good (yes I know this is ugly) way to hack to the private data members of a class? One brute force approach is to copy the header file and in my copy change private to public. But would there be a better way, say doi...

Referencing a pointer in a C++ member function.

Hi, I'm writing a member function that uses a member variable pointer as an iterator. However I want to reference the pointer within the function purely for readability's sake. Like so: /* getNext will return a pos object each time it is called for each node * in the tree. If all nodes have been returned it will return a Pos * objec...

[C++] Is it a good idea to always return references for member variable getters?

If I have a class that has many int, float, and enum member variables, is it considered efficient and/or good practice to return them as references rather than copies, and return constant references where no changes should be made? Or is there a reason I should return them as copies? ...