Confused with object arrays in C

0 votes

I have some Java knowledge and now I am learning C++. I am having troubles as expected but there's a problem.

Here, I am trying to create an array of object "Player" and fill it with values of one. But it gives me error

Player* players = new Player[1];
players[0] = new Player(playerWidth, playerHeight, 20, 1);

Error is something like "the operand "=" matches these operands. Operand types are: Player = Player *"

How do I fix it? Do I need to change my approach

Aug 11, 2022 in C++ by krishna
• 2,820 points
311 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C++

0 votes
1 answer

What is a Class and Object in C++?

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

answered Jun 21, 2022 in C++ by Damon
• 4,960 points
492 views
0 votes
1 answer

please help me with max_element function in c++ stl

You can substitute max for *max eleme ...READ MORE

answered Jun 27, 2022 in C++ by Damon
• 4,960 points
711 views
0 votes
1 answer

What is dynamic initialization of object in c++?

Dynamic initialization occurs when the initialization value is unknown at compile time.  To initialise the variable, it is calculated at runtime. Example, int factorial(int n) { ...READ MORE

answered Aug 2, 2022 in C++ by Damon
• 4,960 points
2,081 views
0 votes
0 answers

How come an array's address is equal to its value in C?

The pointer values and pointer addresses in ...READ MORE

Aug 8, 2022 in C++ by krishna
• 2,820 points
470 views
0 votes
0 answers

declaring a priority_queue in c++ with a custom comparator

I'm attempting to declare a priority queue of nodes using the comparator function bool Compare(Node a, Node b) (which is outside the node class). I presently have the following: priority_queue<Node, vector<Node>, Compare> openSet; I'm receiving Error: "Compare" is not a type name for some reason. Adding priority_queue<Node, vector Node>, bool Compare> to the declaration. gives me the error 'Error: expecting a '>' I've also attempted: priority_queue<Node, vector<Node>, Compare()> openSet; priority_queue<Node, ...READ MORE

Aug 11, 2022 in C++ by Nicholas
• 7,760 points
943 views
0 votes
0 answers

In C, are arrays pointers or used as pointers?

First, look at this code When this is ...READ MORE

Aug 11, 2022 in C++ by krishna
• 2,820 points
503 views
0 votes
0 answers

How do I determine the size of my array in C?

How do I determine the size of ...READ MORE

May 1, 2022 in Others by Kichu
• 19,040 points
455 views
0 votes
0 answers

How to convert a char array to a string?

Converting a C++ string to a char ...READ MORE

Jul 14, 2022 in C++ by Nicholas
• 7,760 points
521 views
0 votes
0 answers

How do I declare a 2d array in C++ using new?

How do I declare a two-dimensional array using new? For example, for a "typical" array, I would:      int* ary = new int[Size] but int** ...READ MORE

Jul 15, 2022 in C++ by Nicholas
• 7,760 points
488 views
0 votes
0 answers

How to declare an array of strings in C++?

I am trying to iterate over all ...READ MORE

Jul 26, 2022 in C++ by Nicholas
• 7,760 points
542 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP