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
0
votes
2 answers

Using lambda in default initializer vs using member function

Is there any difference in using "one-time" lambda in default initializer and using plain old member function? struct A { int i; int j = [&] // something non-trivial, // that requires multiple // statements and depends // on…
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
0
votes
1 answer

C++ Name Resolution in Template Subclass-of-Subclass

I am trying to access base-class data in my C++ code without using the "this" pointer. My classes are templated, and ClassA is the base class for ClassB, which is the base class for ClassC. All classes are publicly derived from their base classes.…
Patrick Kelly
  • 1,301
  • 1
  • 16
  • 25
0
votes
2 answers

invalid use of static data member in constructor parameter list

I have a class something like this: class Foo : public Bar { double v1; double v2; ... public: explicit Foo (double v1_ = 1.0, double v2_ = v1 > 0.0 ? 2.0 : 0.0) : v1(v1_), v2(v2_) { // do something } // do other things }; but I get the…
Duh
  • 87
  • 1
  • 1
  • 12
0
votes
1 answer

Putting data members inside a struct?

I'm bringing some old unmaintained software up to date, and I've noticed a peculiar pattern that I haven't been able to adequately explain. The code in question is written in C++. Normally when I see data members, they exist inside the class…
CMPXCHG8B
  • 497
  • 3
  • 15
0
votes
0 answers

functions in class data members

In PHP (v 5.5.9-1ubuntu4.11) I'm not allowed to initialize data members with functions or arrays of functions. These two violate the PHP syntax on a basis of syntax error, unexpected 'function' (T_FUNCTION), expecting ')': class Foo { var $a =…
Herbert
  • 5,279
  • 5
  • 44
  • 69
0
votes
0 answers

Populating a 2d array with a from a data member of an object, using a list of object

Okay, I am rather new to java and I really need some help! I have a class named Teams and have already have a previously established the List checkedInTeams; but now I need to populate a 2d array with a specific data member from the Teams…
0
votes
1 answer

Enforce safe use of class containing reference or raw pointer

Suppose we have a class that looks like the following. class DoStuffWithRef { DoStuffWithRef(LargeObject& lo) : lo_(lo) {} // a bunch of member functions, some of them useful // [...] private: LargeObject& lo_; }; The class is…
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
0
votes
0 answers

Error using subclass of class with boost::thread data member

I have created the following class #include #include #include class Messaging { public: Messaging(const std::string& newMessage, unsigned long long maxTimeToDeliver = 12):…
user3731622
  • 4,844
  • 8
  • 45
  • 84
0
votes
4 answers

non-static data member initializers c++

non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default] int Red = 255; non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default] int Green =…
user2044600
  • 15
  • 2
  • 7
0
votes
1 answer

Update values of all public variables of class using get_object_vars()

I have class with 100 public members. How can I update them in an automated way, ie without specifying their name. I have tried this and I'm getting variables but the changes made doesn't reflect on actual object. Please advice. class foo { …
Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
0
votes
1 answer

Initial data member values

I was very surprized to see that in the version of Visual C++ that comes with VS2013 the data members of a newly created class seem to be automatically initialized to 0 or null depending on their type. This is new - and very useful! - behaviour in…
user3259248
0
votes
1 answer

C# model encapsulation with serializable

I am using serializable, but cannot leave my private class. [DataContract] public class test { [DataMember] public String name { get; set; } } what problems in leave this class in public. I do not understand this encapsulation, because I…
vrbsm
  • 1,188
  • 15
  • 22
0
votes
3 answers

Constructors accessing private data

Still new to C++ and I'm trying to understand accessing private data, using constructors. How would I display the values of the data members of myClass? Any help would be great. Thanks class NumberClass { public: void func(); // assigns…
jacksonSD
  • 677
  • 2
  • 13
  • 27
0
votes
1 answer

WCF service optional datamember

I have a WCF service which needs to return a Json response: { "Content": { "Id": 817 "Message":"message" }, "Status": "Ok" } Here the message parameter is optional in some cases it exists and in some it doesn't. I tried to get it working using…
Arti
  • 2,993
  • 11
  • 68
  • 121
0
votes
1 answer

Access protected data members of the base class from the derived class

I have a base class and the derived class. I need to access the protected member of the base class in the derived class. However, Eclipse does not allow me to access the data member as if it were a member of a derived class without caring that it…
user592748
  • 1,194
  • 3
  • 21
  • 45