Questions tagged [member]

A member is an element of an object in the object-oriented programming paradigm.

A member is an element of an object in the object-oriented programming paradigm. Member variables are often called fields, while member functions are also called methods.

1754 questions
43
votes
1 answer

Constructor for '' must explicitly initialize the reference member ''

I have this class class CamFeed { public: // constructor CamFeed(ofVideoGrabber &cam); ofVideoGrabber &cam; }; And this constructor: CamFeed::CamFeed(ofVideoGrabber &cam) { this->cam = cam; } I get this error on the…
clankill3r
  • 9,146
  • 20
  • 70
  • 126
42
votes
8 answers

"Incomplete type" in class which has a member of the same type of the class itself

I have a class that should have a private member of the same class, something like: class A { private: A member; } But it tells me that member is an incomplete type. Why? It doesn't tell me incomplete type if I use a pointer, but I'd…
Sterling
  • 3,835
  • 14
  • 48
  • 73
42
votes
9 answers

what is a member vs. a property

A friend who is new to OO programming asked me the difference between a Member and Property, and I was ashamed to admit that I couldn't give him a good answer. Since properties can also be objects themselves, I was left with a general description…
SqlRyan
  • 33,116
  • 33
  • 114
  • 199
41
votes
1 answer

Pointer to class member as template parameter

Is it possible to have non-type template parameter which is actually a pointer to a class member? What I'm looking to do is something like the following: struct Person { Dog dog; }; template struct Strange { // ... }; typedef…
Jonathan Sterling
  • 18,320
  • 12
  • 67
  • 79
39
votes
1 answer

Nested Class Definition in source file

If I have a nested class like so: class MyClass { class NestedClass { public: // nested class members AND definitions here }; // main class members here }; Currently, the definitions of MyClass are in the CPP file…
Samaursa
  • 16,527
  • 21
  • 89
  • 160
38
votes
1 answer

How to initialize a shared_ptr that is a member of a class?

I am not sure about a good way to initialize a shared_ptr that is a member of a class. Can you tell me, whether the way that I choose in C::foo() is fine, or is there a better solution? class A { public: A(); }; class B { public: B(A*…
Igor
  • 26,650
  • 27
  • 89
  • 114
38
votes
4 answers

What is the default value of a member in an array?

I instantiate an array like this: int array[] = new int[4]; What are the default values for those four members? Is it null, 0 or not exists?
dylanmensaert
  • 1,689
  • 5
  • 24
  • 39
37
votes
3 answers

invalid use of non-static member function

I have something like this: class Bar { public: pair one; std::vector cars; Bar(string one, string two, string car); }; class Car { public: string rz; …
Nash
  • 493
  • 1
  • 4
  • 7
35
votes
5 answers

Get a pointer to object's member function

Here is the problem: 1) I have a class like so: class some_class { public: some_type some_value; int some_function(double *a, double *b, int c, int d, void *e); }; 2) Inside some_function, I use some_values from some_class object to get a…
Alex Hoppus
  • 3,821
  • 4
  • 28
  • 47
35
votes
4 answers

class variables is shared across all instances in python?

I started coding in python a week ago, it is my mistake i started coding using oops,classes and objects that soon. I assumed my C++ proficiency will help.... I got bit by the following code class A: var=0 list=[] def __init__(self): …
howtechstuffworks
  • 1,824
  • 4
  • 29
  • 46
34
votes
3 answers

Member variables in ES6 classes

Is there any way to use the ECMAScript6 class notation to declare either a static class variable or a default value for an instance variable? Without class what I have in mind would be written as function MyClass(arg) { if(arg) this.arg = arg;…
MvG
  • 57,380
  • 22
  • 148
  • 276
34
votes
2 answers

PowerShell how to add something on parsed JSON?

I want to add something in my parsed JSON using PowerShell. My code: function ConvertFromJson([string]$file) { [System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") $jsoncontent = Get-Content $file $jsonobj =…
Blank
  • 355
  • 1
  • 3
  • 8
34
votes
3 answers

Why can't we initialize class members at their declaration?

I wonder if there is a reason why we can't initialize members at their declaration. class Foo { int Bar = 42; // this is invalid }; As an equivalent of using constructor initialization lists. class Foo { int Bar; public: Foo() : Bar(42)…
danijar
  • 32,406
  • 45
  • 166
  • 297
34
votes
33 answers

What kind of prefix do you use for member variables?

No doubt, it's essential for understanding code to give member variables a prefix so that they can easily be distinguished from "normal" variables. But what kind of prefix do you use? I have been working on projects where we used m_ as prefix, on…
Thomas Koschel
  • 3,321
  • 9
  • 33
  • 38
32
votes
8 answers

If I delete a class, are its member variables automatically deleted?

I have been researching, and nothing relevant has come up, so I came here. I am trying to avoid memory leaks, so I am wondering: Say I have class MyClass with member ints a and b, and an int array c, which are filled in a member function: class…
Keelx
  • 907
  • 3
  • 17
  • 26