I'm querying for the ID of a field by accessing a class function which someone has already put in place. The result is a object returned with protected member variables. I'm struggling to see how I can access the member variable values outside the class.
...
Hi All,
I'm trying to log if an object in my mutable array is a member of the class NSString. Here is my code:
id obj = [mutArr objectAtIndex:1];
BOOL classMem = [obj isMemberOfClass:[NSString class]];
NSLog(@"%@", classMem);
Instead of printing YES or NO, I get the output (null). Can you please tell me why this is the case?
Than...
Hi,
I am not sure about a good way to initialize a shared_ptr that is a member of a class. Can you tell me, whether the way that I choose in C::foo() is fine, or is there a better solution?
class A
{
public:
A();
};
class B
{
public:
B(A* pa);
};
class C
{
boost::shared_ptr<A> mA;
boost::shared_ptr<B> mB;
void...
I have a template class with a template member function. I want to explicitly instantiate the class to avoid a drastic compilation slowdown. I am using g++ 4.1.2. I get ambiguous template specialization errors from the compiler. This the shortest code which will reproduce the problem:
template <class T, class S >
class Test
{
public:
...
I would like to use Boost Phoenix to generate a lambda function for use in a std::find_if operation on a structure that contains reference-type members. A contrived example is as follows:
struct MyStruct
{
MyStruct() : x(0) {}
int& x;
};
std::vector<MyStruct> AllStructs;
// Search the array for an element for which x == 5...
I've seen people use a trailing underscore for member variables in classes, for instance in the renowned C++ FAQ Lite.
I think that it's purpose is not to mark variables as members, that's what "m_" is for. It's actual purpose is to make it possible to have an accessor method named like the field, like this:
class Foo {
public:
bar...
Hi
I know about gravatar.com, are there any other sites offering similar features?
Thanks
...
#include <map>
#include <iostream>
template <typename T>
class A
{
static std::map<int, int> data;
public:
A()
{
std::cout << data.size() << std::endl;
data[3] = 4;
}
};
template <typename T>
std::map<int, int> A<T>::data;
//std::map<int, int> A<char>::data;
A<char> a;
int main()
{
return 0;
}
What is wrong with this? Wit...
Hi all,
I'm trying to implement a ring buffer with the following struct
/*head, tail are indexes of the head and tail of ring buffer
*count is the number of elements; size is the max size of buffer
*rbArray is an array to pointer of char used to store strings
*/
struct rb{
int head;
int tail;
int count;
int size;
char...
Hi,
Is it possible in C++ to dynamically (during run-time) get a list of all members of the class?
Greetings
...
Hi guys,
currently I am thinking about data encapsulation in C# and I am a little bit confused.
Years ago, when I started to learn programing with C++, my professor told me:
- "Create a class and hide it data members, so it can't be manipulated directly from outside"
Example:
You are parsing an XML file and store the parsed data into ...
I notice that if you have a private member in a class, you can access it in the class methods by just referring to it's name. You do not need to say this.memberName, just memberName works. So is the this keyword optional in the context of member access?
I do see it is useful when you want to clarify the scope - when you have 2 variables...
How would one go about implementing a vanity URL for each user in PHP? I'm implementing my web-app's login system as a tweaked version of the Drax LLP Login system.
So, each user should be able to modify his profile which will finally appear on his vanity URL .. like xyz.com/user.
Any tips / ideas? Thanks..
...
Hi guys,
I am trying to access static member of a class.
my class is:
class A
{
public static $strName = 'A is my name'
public function xyz()
{
..
}
..
}
//Since i have bunch of classes stored in an array
$x = array('A');
echo $x::$strName;
I am getting error while printing. How can i print 'A is my name'...
In my previous question I found two solutions for accessing static members. I would like to know which one is the better way, and why.
Using reflection
Using object methods
using eval
...
Hi,
If I create a class MyClass and it has some private member say MyOtherClass, is it better to make MyOtherClass a pointer or not? What does it mean also to have it as not a pointer in terms of where it is stored in memory? Will the object be created when the class is created?
I noticed that the examples in QT usually declare class ...
I'v created this class here:
//Integer rectangle class
class AguiRectangle {
int x;
int y;
int width;
int height;
public:
bool isEmpty {
return x == 0 && y == 0 &&
width == 0 && height == 0;
}
int getTop() {
return x;
}
int getLeft() {
return y;
}
int ge...
I'd like to do this:
<?php
define('X', 'attribute_name');
// object $thing is created with member attribute_name
echo $thing->X;
?>
Attempting $thing->X, PHP takes X to be a property of $thing, and ignores the fact (rightly so) that it's a define()'d token. That in mind, I had expected $thing->{X} to work, but no dice.
The only solu...
In order to make a deep copy of myArr,
vector <Point> myArr;
where Point is a class with 2 ints as members,
Do I need to do something special? or is ok with
vector <Point> otherArr = myArr;
I need to delete some points in otherArr but at the same time I need all the points in myArr for later usage.
thanks in advance
...
Take this code:
struct mystruct
{
int var;
mystruct() : var(0) {}
};
int main()
{
mystruct ins;
int* p = &ins.var;
*p = 1;
}
So what are some concrete really good examples of uses for the class member pointer?
int X::*p = &X::data; /* p contains offset */
X object;
X *objptr = new X;
int i = o...