Questions tagged [member-variables]

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.)

169 questions
3
votes
4 answers

Declaring a member variable that takes a constructor parameter

// In A.h class A { public: enum eMyEnum{ eOne, eTwo, eThree }; public: A(eMyEnum e); } // In B.h #include "A.h" class B { B(); private: A memberA; } // In B.cpp #include "B.h" B::B(void) : memberA(A::eOne) …
lost_bits1110
  • 2,380
  • 6
  • 33
  • 44
3
votes
2 answers

C++ proper way to inline initialize member variables

Given the example code: struct S { char data[5]; int a; }; When running the "Run code analysis" in Microsoft Visual Studio, It warns to initialize all variables. Now I know you can do this a number of ways, create a default constructor such…
Hex Crown
  • 753
  • 9
  • 22
3
votes
2 answers

how to add member-variable for a specialized version of a template class?

I have a template class, and at least 95% codes of it is same for all types of the template-parameter, unless a member-variable and a function should be added for one specialization. The sample I want to get is following: template class…
3
votes
3 answers

Member variable alias in class template specialization

Let's suppose I'm writing a Vector template class to represent points and vectors in an N-dimensional space. Something like the following: template struct Vector { T data[N]; // ... }; Let's further assume that, for…
3
votes
1 answer

Return value optimization of a member of a local stack variable

I have a piece of generic code that, when instantiated, boils down to: struct A{...}; A f1(){ A ret; std::pair p(ret, 1); p = g(); // g returns a pair, but I am not interested in g return ret; // RVO :) }; As far…
alfC
  • 14,261
  • 4
  • 67
  • 118
3
votes
4 answers

When does a pointer in C figure out the amount of memory it references?

I've been learning about linked lists and the recursive definition of the node struct has been bugging me struct node { struct node *next; int data; }; I guess I've always imagined that since a pointer is typed, it knows both the beginning…
nek28
  • 259
  • 1
  • 2
  • 6
3
votes
3 answers

difference between view reference to member variable and local variable

suppose I have an activity, and it contains a TextView. I can initialize the TextView either to a member variable or to a local variable. is there any memory wise difference between these to initialization ? example : Activity with local view…
droidev
  • 7,352
  • 11
  • 62
  • 94
3
votes
2 answers

Difference between the terms "Instance variable" and "variables declared in Interfaces"

I was reading about Interfaces in a Book and I came upon this Line that confused me. Interfaces are syntactically similar to classes, but they lack instance variables. As far as I know about Interfaces, we can define variables inside an Interface…
Adil
  • 817
  • 1
  • 8
  • 27
3
votes
1 answer

C++ Segfault when accessing member stl map

I've really tried to put off asking this question because it seems like it should be a simple problem, but here goes. I've been chasing a segfault in a new piece of code. I've included the smallest chunk that demonstrates the issue below. The rest…
AlaskaJoslin
  • 760
  • 8
  • 14
3
votes
2 answers

Objects as member variables in a class in C++

I'd like to know what are the best practice to handle object instances as member variables of another class. After reading different posts it seems that, in general, having references to objects as member variables should be avoided, but I'm not…
gcswoosh
  • 1,279
  • 1
  • 15
  • 31
3
votes
2 answers

Set functions won't work for some reason

I'm working on a simple console application to prototype a method of calculating battle between two large units of medieval soldiers. The idea is I'll set up the calculations, and run the program several times with different parameters to get a feel…
3
votes
2 answers

Initialization of member array objects avoiding move constructor

I'm trying to create and initialize a class that contains a member array of a non-trivial class, which contains some state and (around some corners) std::atomic_flag. As of C++11 one should be able to initialize member arrays. The code (stripped…
Damon
  • 67,688
  • 20
  • 135
  • 185
3
votes
3 answers

Can't access public member variables from junit in Java

Hi everybody my problem is the following: I want to write a testunit for a class i have written. For this I have the following Junit code: 1 package ts; 2 import ts.TransitionSystem; 3 import ts.ConcreteTransitionSystem; 4 import…
3
votes
2 answers

Storing C++ Lambda in a member variable to be used as a callback?

I'm trying to implement a c++ function that gets a Lambda callback as a parameter. The thing is, the callback is initiated asynchronously from another function in the same (called) class. I therefore need to store the Lambda in a member variable so…
Amiram Stark
  • 2,208
  • 22
  • 32
3
votes
1 answer

how do you make classes with objects as member variables in matlab?

I have a project in matlab with the following directory structure: +namespace\ @class1\ class1.m @class2\ class2.m mainfile.m in class1.m I have something like the following classdef class1 %readonly variables …
thed0ctor
  • 1,350
  • 4
  • 17
  • 34
1 2
3
11 12