C Object class

0 votes
There is a generic class in Java called "Object" that all classes are subclasses of. I'm trying to make a linked list library (for a school project), and I've only gotten it to work for one type, not multiple, so is there anything similar?

EDIT: I'd post the code, but I don't have it with me right now.
Jun 2 in C++ by Nicholas
• 2,460 points
13 views

1 answer to this question.

0 votes

No, there is no generic base class in C++.

You can create your own and derive classes from it, but in order to take advantage of polymorphism, you must keep collections of pointers (or smart pointers).

 After re-examining your question, I must mention std::list.

If you want a list that can specialize on multiple types, you use templates (of which std::list is one):

std::list<classA> a;
std::list<classB> b;

If you need a list that can hold multiple types in a single instance, use the base class approach:

std::list<Base*> x;
answered Jun 2 by Damon
• 3,580 points

Related Questions In C++

0 votes
1 answer

In C++, what is a virtual base class?

When employing multiple inheritance, virtual base classes are used to prevent several "instances" of a particular class from appearing in an inheritance hierarchy. Consider the following example: class A { public: void Foo() {} ...READ MORE

answered Jun 10 in C++ by Damon
• 3,580 points
10 views
0 votes
1 answer

What data structure is inside std::map in C++?

An associative container is std::map. The standard's ...READ MORE

answered May 31 in C++ by Damon
• 3,580 points
19 views
0 votes
1 answer

C++ `this` pointer

Pointer variables are used to store the ...READ MORE

answered May 31 in C++ by Damon
• 3,580 points
13 views
0 votes
1 answer

Easiest way to convert int to string in C++

C++ adds std::stoi (and variants for each numeric type) and std::to string, which are the C equivalents of atoi and itoa but expressed in terms of std::string #include <string> std::string s = std::to_string(42); Is therefore ...READ MORE

answered Jun 1 in C++ by Damon
• 3,580 points
25 views
0 votes
1 answer

The difference between Classes, Objects, and Instances

A class is a type of blueprint ...READ MORE

answered Jun 7 in Java by pranav
• 2,320 points
56 views
0 votes
1 answer

Python class inherits object

Python 3.x: class MyClass(object): = new-style class class MyClass: = new-style ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,080 points
240 views
0 votes
1 answer

What are the prerequisites to learn Hadoop in java perspective?

In my day job, I've just spent ...READ MORE

answered Oct 11, 2018 in Big Data Hadoop by Frankie
• 9,830 points
323 views
0 votes
1 answer

How can we compare objects by multiple fields in Java?

You can implement a Comparator which compares two Person objects, and ...READ MORE

answered Jan 9, 2019 in Java by Daisy
• 8,120 points
2,126 views
0 votes
1 answer

What is a Class and Object in C++?

A Class is like a blueprint, an ...READ MORE

answered Jun 21 in C++ by Damon
• 3,580 points
13 views
0 votes
1 answer

Declare abstract class in c++

An abstract class is one that is intended to be used as a base class .  At least one pure virtual function exists in an abstract class.  A pure virtual function is declared in the class declaration by using a pure specifier (= 0) in the declaration of a virtual member function. Here is an example of an abstract class: class AB { public: virtual void f() ...READ MORE

answered May 31 in C++ by Damon
• 3,580 points
20 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP