A member variable is a member of a type and belongs to that type's state. (Contrast with a "local variable", defined inside a method.)
Questions tagged [member-variables]
169 questions
1
vote
4 answers
sizeof in static const member initialization
I have such code:
class A
{
public:
unsigned long a;
static const unsigned long b = sizeof(a); // "error C2327: 'A::a' : is not a type name, static, or enumerator" in VC++
};
I got compiler error in VC++ and no errors in IAR.
Which…

vadim b.
- 31
- 3
1
vote
3 answers
Idiom for default initialization depending on type
I have a template class that takes default member values.
template
struct A{
T val = {"val"};
};
However sometimes the default values do not make sense, for example:
A a1; // cannot initialize int from "val"
Is…

alfC
- 14,261
- 4
- 67
- 118
1
vote
1 answer
Copy an object and make both share a member variable (C++)
I have been thinking and searching this but I can't solve this question.
I would like an object that when copied into another object, both objects share certain member variable. So, when I change the value of the member variable of object1, it's…

Anselmo GPP
- 425
- 2
- 21
1
vote
1 answer
Private variable in AppComponent constructor -> NO HTML/View?
Problem:
When adding (Visual Code autocompleted/-added) a variable (private _dataService: DataService) in AppComponent constructor(…) { } (because I used it down below) somehow the whole UI output vanishes.
When taken out of it (or moved above), all…

Tha Brad
- 148
- 12
1
vote
1 answer
How Can We Determine Whether an Attribute belongs to the Instance or to the Class?
Intro
In Python I want to get a list of all attributes of an object which belong to the class and not to the instance (a list of all static attributes).
Some code to test potential solutions with:
class Klass:
static_var = 'static_var…

Toothpick Anemone
- 4,290
- 2
- 20
- 42
1
vote
3 answers
Should I create a new variable or always access the data from a class object?
Let's begin with an example (just for the sake of explanation)
public void mySecretOperation() {
User user = new User();
if (user.getAge() > 2 && user.getAge() < 5) {
//TODO : do something...
}
if (user.getAge() > 12 &&…

Nishant Thapliyal
- 1,540
- 17
- 28
1
vote
1 answer
Android Studio IDE | Extract member variables and methods from Java class?
Im new to Android Studio IDE.
I just have a question, its is there a way to extract all member variables and methods in a java class that had been written before?
I mean suppose that I had a 6000-lines java class and it has so many member variables…

Impossible
- 23
- 3
1
vote
1 answer
mem_fn to mem_fn of member
This is a follow-up question to
mem_fn to function of member object
This is the current code.
#include
#include
#include
struct Int
{
Int(int _x = 0) : x(_x) {}
int GetInt() const { return x; }
int…

Thomas B.
- 691
- 4
- 15
1
vote
1 answer
the order of member variable in class template
I've defined a class template and a function,
template class Base {
public:
Base(F ff): f(ff) {}
template auto operator() (Ps... ps) const -> decltype(f(ps...)) { return f(ps...); }
private:
…

Vogel_guo
- 51
- 2
- 8
1
vote
1 answer
Function to extract variable values from data frame
I have R data.frame containing variable_name and variable_values. I'm writing a function to extract each variable_name and assign corresponding
variable_values and keep it in memory for later use. However, I keep getting error message such as this…

R. zqkal
- 57
- 4
1
vote
0 answers
PHP membervariables DateObject modify
In this code
$start = $this->getStart();
var_dump($start);
$start->modify('Monday this week');
var_dump($this->getStart());
-
public function getStart()
{
return $this->start;
}
how is it possible, that the second dump actually shows the…

skymeissner
- 228
- 1
- 9
1
vote
2 answers
Populate an Array of Structure Variables by Reading a Delimited Text File
I have a text file called games.txt that contains the details of many computer game matches. Each line represents:
Player1Score, Player1Name, Player1Age, Player 2Score, Player2Name, Player2Age
Here is an example of 3 lines (there are a total of…

leah
- 21
- 4
1
vote
4 answers
Java : object of a class as instance variable in same class
Being a beginner, I have a conceptual doubt. What is the use of a class type object as member/instance variable in the same class?
Something like this :
class MyClass {
static MyClass ref;
String[] arguments;
public static void main(String[] args)…

javaeager
- 21
- 1
- 3
1
vote
4 answers
Access reading error when using class member variable
I have a class with private member variables declared in a header file. In my constructor, I pass in some filenames and create other objects using those names. This works fine. When I try to add another member variable, however, and initialize it in…

bsg
- 825
- 2
- 14
- 34
1
vote
3 answers
Change value of member variable within function - C++
I'm doing some collision detection and handling for a GBA game I'm writing and I'm running into problems with putting the handling part into a function.
I'm trying to change the value of a member variable (in this case Player.global_x), however…

DeanoMachino
- 59
- 2
- 12