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
259
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,613
  • 2
  • 13
  • 5
235
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
  • 5,014
  • 6
  • 26
  • 27
137
votes
4 answers

Should I use instance or class attributes if there will only be one instance?

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
  • 89,107
  • 111
  • 320
  • 448
110
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
  • 22,195
  • 68
  • 188
  • 269
106
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,746
  • 5
  • 25
  • 30
98
votes
8 answers

What is the difference between "::" "." and "->" in c++

I created a class called Kwadrat. The class has three int fields. My Development Environment suggests that I access the fields from Kwadrat created objects via the :: & -> operators. I tried both operators, and found that the -> operator is able to…
Yoda
  • 17,363
  • 67
  • 204
  • 344
84
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,713
  • 5
  • 25
  • 25
76
votes
4 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
  • 1,201
  • 1
  • 10
  • 14
73
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
  • 12,496
  • 23
  • 93
  • 160
60
votes
3 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
  • 707
  • 1
  • 5
  • 8
59
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
  • 881
  • 2
  • 7
  • 6
53
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,538
  • 5
  • 24
  • 31
50
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
  • 17,157
  • 35
  • 107
  • 145
49
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
  • 563
  • 1
  • 5
  • 7
1
2 3
99 100