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
1
vote
3 answers

When manipulating data members: which of the following is considered best practice

I want to start adopting best practice and have seen class members being manipulated in different ways. I am not aware of any subtle nor significant differences in the following example. I wish to clarify an optimal approach if any of the two or…
andres
  • 301
  • 6
  • 21
1
vote
1 answer

Explanation needed for the in_addr strcuture

I do not understand MSDN's documentation for it's member's at all. It ask for things I've never done before like the S_un_b member needs The IPv4 address of the host formatted as four u_chars. which doesn't really make sense to me unless it means…
1
vote
5 answers

Why/When would I want to use a class data member without defining an object of the class?

It is possible in C++ to use a data member of a class without defining an object of that class, by defining that data member in the public section as a static variable, as in the code sample below. The question is, why/when would I want to do this?…
A_Matar
  • 2,210
  • 3
  • 31
  • 53
1
vote
2 answers

Initialization of 2D array data member

I have a program like this: class A { int a[2][3]; public: A(int b[2][3]): a(b) {}; }; int main() { int b[2][3]; A myclass(b); return 1; } The compiler says: 1.cpp: In constructor 'A::A(int (*)[3])': 1.cpp:5:22: error: incompatible…
klm123
  • 12,105
  • 14
  • 57
  • 95
1
vote
2 answers

How to specify member pointer to an array element?

I have a library with function, which looks like this: template void NastyFunction(S1 *array, EntryType S1::* member1); So if I have an array of structs like: struct TData { float a; float b[10]; }; TData dataArray[N]; I can…
klm123
  • 12,105
  • 14
  • 57
  • 95
1
vote
1 answer

How to write members of a class to a binary file using cpp?

I'm writing a small back-end in cpp where I have to write some crossword data into a binary file. I have created an XWPuzzle class with all its data members public, and xWord is an object of this class. Here is the piece of code with which I'm…
artfuldev
  • 1,118
  • 1
  • 13
  • 25
1
vote
3 answers

Access non static data member outside class

Is it possible to access non static data members outside their class? Say you have an example like the following. I know it does not make much sense as an example, but I just want to understand how to access a non static data member. If the…
FranXh
  • 4,481
  • 20
  • 59
  • 78
1
vote
1 answer

Alternatives to protected data members, specific case study

It seems to be the prevailing opinion that using protected data members is a bad idea. I'm wondering what a good alternative would be in a specific case. Take the following class called CModule, which represents a audio module (Amiga-style tracker…
Unimportant
  • 2,076
  • 14
  • 19
0
votes
2 answers

ActionScript 3.0: Sharing attributes in classes

Would anyone be able to help me out with this research for my actionscript class? Ive been asked to research the relationships between classes but having trouble understanding it. Within my code, the class A creates an instance of class B inside it,…
0
votes
1 answer

Change DataMember property on WCF web service depending on input/output?

Scenario: An entity from data model is passed into a WCF Web Service with various information, saved into a database and then returned back with the object fully populated with additional information. public class Request { public virtual…
Damien Dennehy
  • 3,937
  • 2
  • 19
  • 21
0
votes
3 answers

Is it appropriate to declare a non-static constant data member inside a class while coding?

data member inside a class can be const but only if its static. otherwise we need to have a constructor to initialize a constant inside a class. can we declare a const data member inside a class? //this was an interview question It seems to me that…
munish
  • 4,505
  • 14
  • 53
  • 83
0
votes
0 answers

How to access the field variable of a class through a generic object?

I've been testing out generic programming in Java. Here is a snippet of my code: public class Vehicle { private T make; private String color; private int year; private String brand; private String model; …
0
votes
2 answers

Is there an implicit pointer to base class subobject when accessing one of its members?

If we had this code: class Base { int anint; float afloat; }; class Derived : Base { //inherited member variables... }; I have been told that members of Base would be inherited to Derived and these the inherited members in Derived are actually…
user8626782
0
votes
1 answer

How to preform search operation from combobox using data/value member in Visual Studio 2012 C#

I am at beginner level at this kind of programming so I believe that someone of you will know how to resolve this problem I'm having. I have a small project in Visual Studio that is connected with Oracle Database 11g Express, and I want to perform a…
0
votes
0 answers

what is redefining static variable in c++?

It's said that, Once the definition for static data member is made, user cannot redefine it. what does it exactly mean? As I am able to assign anything to it #include class X { public: static int i; X() { i =…
user7496691