Why are int primitive and Integer Class both supported in c++?

Why are int primitive and Integer Class both supported in C++? How does supporting a primitive break the object-oriented paradigm? Can someone please help or refer me to some articles about these concepts?

What Integer Class? Can you provide a link to documentation of it?

1 Like

@SamuelCalifornia,

“This class provides the ability to have integer values that are thousands of digits long, or longer.”

@Jeff_Mott,
Thanks for your input. How does supporting a primitive break the object-oriented paradigm?

It doesn’t. Why do you think it does?

1 Like

@Jeff_Mott,

So you mean to tell me that the difference between an Integer Class and primitive int is that the Integer class can store bigger numbers in memory space than simple primitive int data type? I think I get why an int primitive doesn’t break the paradigm. It’s because it’s just int data type compared to Integer class which is more relevant to creating an instance of class or OOP. Care to explain your reasoning why it doesn’t break the paradigm and a really good article supporting your claims? That would help me so much !!!

In C++, “class” is synomous with “type”. By defining a new class, you’re really defining a new type.

Here’s an e excerpt from the guy who invented C++.

1 Like

@Jeff_Mott,

You claim that supporting an **int primitive doesn’t break the OOP paradigm, but let’s figure out why. For example, if I said Integer number1= new Integer(2503); this not the same as initializing an int variable named number1 and setting it equal to 2503. For example, int number1= 2503; This is because an the instance of Integer class is only reserving memory for an object named “number1,” while the primitive int variable named “number1” holds 2503 as a value for that variable. So basically what I am trying to say is that since OOP is creating an instance of class, Integer class would align up more to OOP than just storing a variable’s value into some data type variable. The primitive example should then break OOP paradigm.

Built-in types and user-defined types can both be used in the same way. They can both hold their value directly:

int bi = 2503;
Integer udi = 2503;

Or they can both be pointers to values allocated elsewhere:

int* bip = new int(2503);
Integer* udip = new Integer(2503);

So in C++, built-in types and user-defined types (classes) are on equal footing. When you define a class, you’re defining a type, no different than an int.

1 Like

@Jeff_Mott,
So what you are telling me is that an int primitive doesn’t break the paradigm because it acts the same way in which an Integer class can act?

Right.

They are not. The article you are looking at describes a class that someone wrote. The Integer Class in the article is not part of the C++ standard. Saying that C++ supports the Integer Class is like saying that C++ supports the Solitaire game when someone writes a Solitaire game using C++.

No. C++ includes all the (built-in) “types” that C has and C has no classes. All classes are types but not all types are classes.

The built-in types, such as int, from C are not classes. They don’t have methods or any members.

As best as I understand, your question assumes that the Integer Class is part of the C++ standard. If so then that is a fundamental flaw and it is futile to discuss it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.