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.

1628 questions
222
votes
14 answers

Static nested class in Java, why?

I was looking at the Java code for LinkedList and noticed that it made use of a static nested class, Entry. public class LinkedList ... { ... private static class Entry { ... } } What is the reason for using a static nested class, rather…
David Turner
  • 4,874
  • 5
  • 24
  • 26
219
votes
3 answers

cout is not a member of std

I'm practicing using mulitple files and header files etc. So I have this project which takes two numbers and then adds them. Pretty simple. Here are my files: main.cpp #include #include "add.h" int main() { int x = readNumber(); …
Paul Hannon
  • 2,213
  • 2
  • 10
  • 5
129
votes
4 answers

Instance variables vs. class variables in Python

I have Python classes, of which I need only one instance at runtime, so it would be sufficient to have the attributes only once per class and not per instance. If there would be more than one instance (which won't happen), all instance should have…
deamon
  • 78,414
  • 98
  • 279
  • 415
109
votes
6 answers

php static function

I have a question regarding static function in php. let's assume that I have a class class test { public function sayHi() { echo 'hi'; } } if I do test::sayHi(); it works without a problem. class test { public static function…
Moon
  • 20,835
  • 65
  • 174
  • 263
94
votes
6 answers

C++ callback using class member

I know this has been asked so many times, and because of that it's difficult to dig through the cruft and find a simple example of what works. I've got this, it's simple and it works for MyClass... #include using std::cout; using…
BentFX
  • 2,546
  • 2
  • 23
  • 29
78
votes
5 answers

C++ inline member function in .cpp file

I know that inline member functions by definition should go into the header. But what if it's not possible to put the implementation of the function into the header? Let's take this situation: File A.h #pragma once #include "B.h" class A{ B…
Mat
  • 2,473
  • 5
  • 23
  • 24
66
votes
3 answers

default visibility of C++ class/struct members

In C++, why is private the default visibility for members of classes, but public for structs?
S I
  • 961
  • 1
  • 7
  • 13
54
votes
6 answers

Why can't we initialize members inside a structure?

Why can't we initialize members inside a structure ? example: struct s { int i = 10; };
Santhosh
  • 821
  • 2
  • 7
  • 6
48
votes
4 answers

What's the difference between the square bracket and dot notations in Python?

I come from a Javascript background (where properties can be accessed through both . and [] notation), so please forgive me, but what, exactly, is the difference between the two in Python? From my experimentation it seeems that [] should always be…
Startec
  • 10,304
  • 15
  • 74
  • 131
47
votes
11 answers

Class members that are objects - Pointers or not? C++

If I create a class MyClass and it has some private member say MyOtherClass, is it better to make MyOtherClass a pointer or not? What does it mean also to have it as not a pointer in terms of where it is stored in memory? Will the object be created…
Mark
  • 1,448
  • 5
  • 21
  • 31
45
votes
2 answers

I can't reach any class member from a nested class in Kotlin

I want to access a member of the MainFragment class from PersonAdapter class but none of them are available. I tried making both the classes and the members public and private also but so far nothing worked. I guess I'm missing something obvious…
ftibi93
  • 457
  • 1
  • 4
  • 8
45
votes
5 answers

How do I access static member of a class?

I am trying to access static member of a class. my class is: class A { public static $strName = 'A is my name' public function xyz() { .. } .. } //Since I have bunch of classes stored in an array $x = array('A'); echo…
KoolKabin
  • 15,407
  • 35
  • 103
  • 144
44
votes
7 answers

Trailing underscores for member variables in C++

I've seen people use a trailing underscore for member variables in classes, for instance in the renowned C++ FAQ Lite. I think that it's purpose is not to mark variables as members, that's what "m_" is for. It's actual purpose is to make it possible…
eomer
  • 513
  • 1
  • 5
  • 7
39
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,585
  • 13
  • 44
  • 72
1
2 3
99 100