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

How should I pass an object to a class to check for collisions?

I'm making a Breakout game in C++ using the SFML library, I have a "paddle" class as well as a "ball" class, both being updated and rendered in a "game" class, which uses a render window from a "window" class. My issue is that in order to determine…
JackMills
  • 21
  • 1
2
votes
1 answer

Regular class global variable being shared between object instances - help!

I have just started learning objective c having a little Java experience and this site has been really helpful for answering loads of my questions, but I've hit an issue I can't quite fathom. Theres a fair amount to be read on the topic but I can't…
2
votes
1 answer

invalid use of non-static data member c++ student

I'm a noob who is just starting with programming and I was wondering why do I get an error message which says: invalid use of non-static data member 'Lavirint::n'? class Lavirint{ private: int n, m; bool mapa[n + 2][m + 2]; //is this…
2
votes
3 answers

Define data members within constructor

I have got this little snippet of code, I want to be able to define each array element as a new data member. class Core_User { protected $data_members = array( 'id' => '%d', 'email' => '"%s"', …
bertsisterwanda
  • 153
  • 1
  • 1
  • 10
2
votes
3 answers

Encapsulating data so the setter is private and getter is public

I was wondering how it is best to create a data entity in C++, where the "setter" is private and "getter" is public. i.e the creator of the entity should be able to set the data, but the user/consumer/client is only able to get the data. Lets…
user3594184
  • 805
  • 2
  • 9
  • 15
2
votes
1 answer

What is a reasonable way of keeping track of multiple windows in PyQt?

I'm writing a PyQt application that shall feature multiple windows. Right now, I am interested in having one of two windows open at a time (so a click of a button in one window causes a switch to the other window). What is a reasonable way of…
d3pd
  • 7,935
  • 24
  • 76
  • 127
2
votes
2 answers

Array of pointers to data members

class A { float m_Period; // a1 float m_Scale; // a2 }; I can have pointer to a data member like this: float A::*pFloat; For reason of handle members in cycle i need an array of such pointers. How to do this.
Yola
  • 18,496
  • 11
  • 65
  • 106
2
votes
3 answers

Why can the derived class have the same data members from the base class?

As having same data members in both base and derived classes, it creates a lot of confusion and requires usage of the scope resolution operator to resolve conflicts. So why is it allowed in C++? Can anyone show me the need for this?
nbbk
  • 1,102
  • 2
  • 14
  • 32
2
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
  • 564
  • 1
  • 6
  • 13
2
votes
3 answers

"class::data member is private" error, but I'm operating on it with a member function?

I'm fairly new to C++, and I don't understand what is triggering this error: /home/---/Documents/C++/---_lab2/lab2c.cpp||In function ‘int main()’:| Line 9: error: ‘float circle::x1’ is private Line 58: error: within this context I know the data…
nmar
  • 135
  • 1
  • 1
  • 7
1
vote
0 answers

Android Data Members cleared after call to startActivityForResult

I have a class Asset which has some Strings and an Integer count. On a button press I set count and call startActivityForResult. Once in onActivityResult count is 0. public class MainActivity extends Activity { private Button BtnScanBc; private…
subforry
  • 70
  • 5
1
vote
1 answer

Access variables in struct from void pointer

I was wondering if there is a way to access a data member within a struct that is being pointed to by a void*? What I'm trying to explain will hopefully be more apparent in my example code: int main() { struct S { int val; }; S s; …
demogorgon
  • 474
  • 4
  • 20
1
vote
1 answer

Why non-static data members of class cannot be given default values using '( )'?

I'm just going through the basic OOP concepts in C++ and came across the following: class A{ public: int i(20); //line 1 }; int main() { int j(20); cout<
infinite loop
  • 1,309
  • 9
  • 19
1
vote
2 answers

Using an array to store only Names of the data members of a class in C++

Suppose I have a class as class A { char a[15], b[11],c[17]; public: void names(); } void A :: names() { char x[20]; x=a; cout<
1
vote
2 answers

When to use which data member initialization in C++

Considering this program: #include class C { public: C(void): a(1) { a=2; } int a{3}; }; int main(void) { C c{}; std::cout << c.a; // 2 } I can see three forms of data member initialization: using a member…
hgiesel
  • 5,430
  • 2
  • 29
  • 56