Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an object be considered as a variable?

Tags:

c++

I'm having some trouble keeping apart the terms class, object, variable and datatype.

can a class be considered as a datatype? can an object be considered as a variable?

Also, what's the technical difference?

like image 824
xcrypt Avatar asked Oct 18 '11 18:10

xcrypt


People also ask

Is variable and object are same?

Simple variable can only hold one value (string, number, boolean etc). Object can hold pairs of variables and values, also that object model can be used for another object just different values, and oop is based on that, using same code multiple times with diff value s without rewriting it.

What are object variables called?

The variables that the object contains are called instance variables. The methods (that is, subroutines) that the object contains are called instance methods.

Is object a variable of class?

An object variable or instance member belongs to a specific instance of a class. That is to say that every instance has its own copy of that piece of data. A class variable or static member is shared by every instance of the class.

Is an object a variable in Python?

Object (a.k.a. value): a "thing". Lists, dictionaries, strings, numbers, tuples, functions, and modules are all objects. "Object" defies definition because everything is an object in Python. Variable (a.k.a. name): a name used to refer to an object.


2 Answers

There are two different uses of these terms:

  • Casual use:

    • Class: Abstract data type with methods and fields.
    • Object: Instance of a class.
    • Variable: Language-level name (i.e: name given by a programmer) for some piece of storage.
    • Datatype: Type that a variable (or some unnamed piece of storage) can have.
  • C/C++ standard use (comes from the C standard, which isn't an Object-Oriented Language:

    • Object: Some piece of storage, whether it has a name or not.
    • Object of Class Type: Some piece of storage whose datatype is class(=struct).
like image 153
ninjalj Avatar answered Oct 15 '22 15:10

ninjalj


Variables are objects with direct names.

int i;

i is a variable and an object.

int* p = new int;

*p is an object but not a variable.

Classes and types are pretty much identical, except types includes primitive types like int. Realistically, they're pretty interchangable- as well as variable/object. The reality of the C++ Standard is that very few rules apply differently to classes than to types, and variables than to objects.

like image 35
Puppy Avatar answered Oct 15 '22 17:10

Puppy