member-variables Questions

10

Solved

How can I make methods and data members private in Python? Or doesn't Python support private members?
Meara asked 14/1, 2010 at 13:6

5

Solved

The question may seem a little bit weird but I'll try to contestualize a little bit the use case. Suppose you have a generic implementation of a two-dimensional (Cartesian) field with dimensions d...
Penick asked 24/7, 2019 at 19:48

5

Solved

Consider the following (simplified) situation: class Foo { private: int evenA; int evenB; int evenSum; public: Foo(int a, int b) : evenA(a-(a%2)), evenB(b-(b%2)), evenSum(evenA+evenB) { } };...
Keynesianism asked 23/5, 2012 at 12:55

7

Solved

When trying to change it,throw an exception.
Sale asked 26/2, 2010 at 18:12

7

Solved

I am just learning Python and I come from a C background so please let me know if I have any confusion / mix up between both. Assume I have the following class: class Node(object): def __init__(...
Excreta asked 13/9, 2012 at 15:25

2

Solved

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 ...
Oneeyed asked 23/5, 2019 at 8:45

2

What is a member variable? Is a member variable and an instance variable the same thing? An instance variable is a variable declared in a class and accessed throughout the code, right?
Cudbear asked 11/5, 2018 at 7:36

5

Solved

Is there any meaningful distinction between: class A(object): foo = 5 # some default value vs. class B(object): def __init__(self, foo=5): self.foo = foo If you're creating a lot of instan...
Vireo asked 16/10, 2008 at 0:23

1

Solved

This is a follow-up question to mem_fn to function of member object This is the current code. #include <vector> #include <algorithm> #include <functional> struct Int { Int(in...
Manama asked 19/6, 2017 at 11:12

3

Solved

I was tinkering around with the std::mem_fn and couldn't manage to bind it to data/functions of an member of a struct (one layer deeper). I hope that the code shows the problem better than I can d...
Borderer asked 19/6, 2017 at 8:31

4

Solved

Consider the following two classes: class LunchBox { public: std::vector<Apple> m_apples; }; and class ClassRoom { public: std::vector<Student> m_students; }; The classes are ...
Dig asked 7/5, 2017 at 3:40

5

Solved

Ok, so I'm very new at C++ programming, and I've been looking around for a couple days for a decisive answer for this. WHEN should I declare member variables on the heap vs. the stack? Most of the ...
Docent asked 13/7, 2012 at 19:59

4

Solved

To start, I have something like this: class Test { std::vector<int> a, b; void caller(...) { callee(...); } void callee(...) { /* Do stuff with 'a' */ } } What I wanted is to have a funct...
Troika asked 3/11, 2016 at 12:34

1

Solved

I have a class I'm converting: class MyClass { public:: void foo( void ) { static const char* bar[][3] = { NULL }; func( bar ); } }; Now I want to make bar a member variable, but because th...

3

Solved

The following is said to be better than having First() and Second() as public members. I believe this is nearly as bad. // Example 17-3(b): Proper encapsulation, initially with inline accessors. La...
Quad asked 4/11, 2011 at 6:13

4

Solved

I've seen most people use member variables in a class like : string _foo; public string foo { get { return _foo; }; private set { _foo = value}; } But what's the difference of that to this? pub...
Inelegance asked 25/2, 2014 at 10:6

4

Solved

How would you write a copy constructor for a class with interface member variables? For instance: public class House{ // IAnimal is an interface IAnimal pet; public House(IAnimal pet){ this...
Fernferna asked 12/6, 2013 at 21:24

1

I have started reading the "Beginning python from novice to professional" by Magnus Lie Hetland, and what struck me today is an ability of an objects to create new member variables, even though tho...
Tongue asked 11/6, 2013 at 11:57

5

Solved

I'm a little new to C#, but I have a fairly extensive background in programming. What I'm trying to do: Define different MapTiles for a game. I've defined the base MapTile class like this: public...
Spirketing asked 16/1, 2013 at 22:40

2

Neither g++ (4.4 and 4.6) nor clang++ (3.2) nor coverity, with -Wall and -Wextra (+ some others) or -Weverything respectively gives me a warning for the following code snippet: class B { char *t2...
Bustee asked 3/1, 2013 at 12:47

7

Solved

If I have a class that has many int, float, and enum data members, is it considered efficient and/or good practice to return them as references rather than copies, and return constant references wh...
Bartolomeo asked 19/9, 2010 at 5:35

3

Solved

I was wondering how someone would name the member field that began with initials as opposed to words. public class MyClass { // I know this is how it is for a member field with words. private S...
Lycopodium asked 30/7, 2012 at 13:34

6

Solved

I'm making a very simple class to represent positions in 3D space. Currently, I'm just letting the user access and modify the individual X, Y and Z values directly. In other words, they're public ...
Dacey asked 29/6, 2011 at 23:41

2

Solved

I'm making a simple threaded server application in C++, thing is, I use libconfig++ to parse my configuration files. Well, libconfig doesn't support multithreading, thus I'm using two wrapper class...

3

Solved

I have a templated container class, something like this toy code: template <class ItemType> class MyVector { public: MyVector() : _numItems(0), _items(NULL) {/* empty */} /** Returns a re...
Mafalda asked 17/6, 2011 at 5:53

© 2022 - 2024 — McMap. All rights reserved.