Questions tagged [data-members]

In Object Oriented Programming, data members are the data contained by the object. They are also known as fields or member variables.

In Object Oriented Programming, data members are the data contained by the object. They are also known as fields or member variables.

68 questions
37
votes
1 answer

Can a std::function store pointers to data members?

From cppreference, I found that: Class template std::function is a general-purpose polymorphic function wrapper. Instances of std::function can store, copy, and invoke any Callable target -- functions, lambda expressions, bind expressions, or other…
skypjack
  • 45,296
  • 16
  • 80
  • 161
17
votes
12 answers

How to access private data members outside the class without making "friend"s?

I have a class A as mentioned below:- class A{ int iData; }; I neither want to create member function nor inherit the above class A nor change the specifier of iData. My doubts:- How to access iData of an object say obj1 which is an instance…
Abhineet
  • 6,149
  • 10
  • 32
  • 51
9
votes
2 answers

Does C# resolve dependencies among static data members automatically?

If one static data member depends on another static data member, does C#/.NET guarantee the depended static member is initialized before the dependent member? For example, we have one class like: class Foo { public static string a = "abc"; …
Morgan Cheng
  • 66,562
  • 63
  • 166
  • 223
8
votes
2 answers

Lifetime extension of temporaries' data members and API design

Suppose I have a cross-platform Path class like: class Path { public: // ... Path parent() const; // e.g., /foo/bar -> /foo std::string const& as_utf8() const { return path; } private: std::string…
Paul J. Lucas
  • 6,511
  • 5
  • 41
  • 77
7
votes
3 answers

Why isn't the const qualifier working on pointer members on const objects?

I know this has been asked a lot, but the only answers I could find was when the const-ness was actually casted away using (int*) or similar. Why isn't the const qualifier working on pointer type member variables on const objects when no cast is…
Oskar N.
  • 7,917
  • 2
  • 20
  • 21
7
votes
1 answer

Is there any benifit in using DataContract and DataMember attributes while working with Asp.net Web API?

Many time i saw that developer are using DataContract and DataMember Attributes for their Asp.net Web API model? What are the differences and best practices?
Cruiser KID
  • 1,140
  • 1
  • 11
  • 25
5
votes
4 answers

Automatically-generated Python constructor

I have countless Python classes from various projects from SQLAlchemy (and a couple from Pygame as well), and I recently noticed a pattern in many of them: their constructors always went something like this: class Foo(Base): def __init__(self,…
mmirate
  • 600
  • 5
  • 19
4
votes
2 answers

Pointer to members from Bruce Eckel's Thinking in C++

The following is a paragraph from Bruce Eckel's Thinking in C++ (volume 1, 2nd edition, chapter 11) under the heading "Pointers to members": …a pointer needs an address, but there is no "address" inside the class; selecting the member of class…
user388338
  • 709
  • 2
  • 6
  • 11
4
votes
1 answer

C++: static array inside class having unknown size

I wasn't familiar with this. I searched it on google but didn't find my answer. So, posting my question. Just tried following program: #include class test { static char a[]; static int b[]; }; int main() { test t; } It…
Destructor
  • 13,235
  • 8
  • 48
  • 108
3
votes
3 answers

Mapping data members of a class

I am trying to design a data stuctures, which would enhance/supplement an existing one by storing some additional data about it's members. Let's say we have: class A { int x; string y; }; And we want to have a GUI component associated with it, so…
luk32
  • 15,002
  • 33
  • 58
3
votes
1 answer

Static (possibly constexpr) data member lambda

The following code does not compile: struct object { static constexpr auto f; }; constexpr auto object::f = [](auto&& x){x += 1;}; neither this one: struct object { static constexpr auto f = [](auto&& x){x += 1;}; }; but this does (when…
Vincent
  • 50,257
  • 51
  • 171
  • 339
3
votes
2 answers

Initializing Data Members with a Member Function

I have today learned the very useful new feature of C++ 11 which allows direct initialization of data members in the class declaration: class file_name { public: file_name(const char *input_file_name); ~file_name(); private: …
user3259248
3
votes
4 answers

Does C# just copy field data on assigning to another field or refers to the data?

At assigning one field to another, does the C# just copy data over, or actually creates link? In this article there's an example of game engine structure. The coder there has components contain their parent. In C#, do they just contain the parent…
Johnny
  • 869
  • 2
  • 13
  • 23
3
votes
7 answers

Can java private data members be accessed from outside the class?

Possible Duplicate: Is it possible in Java to access private fields via reflection Is there any way so that we can call the private data members of a class in java, can be accessed outside the class. I want this for a tricky question banks. As…
Aarun
  • 1,017
  • 1
  • 8
  • 12
3
votes
4 answers

Do you use Data Members or Public Properties from within the Class itself?

If I have a simple class setup like this: class MyClass { private string _myName = string.Empty; public string MyName { get { return _myName; } } public void DoSomething() { //…
John Bubriski
  • 18,881
  • 34
  • 115
  • 167
1
2 3 4 5