Code error in class – CSKC
Sign In

Search

Solved Problem #CPP#5179    siteicon   siteicon  

Problem Statement - Code error in class

Find error (if any) in the following class definition.

Class PLAY
{
ย ย int number_of_actors=5;
  void set_actor_count()
  {
    number_of_actors=10;
  }
};

Solution

TC++ #5179

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

//Error 1
Class PLAY
Here it should be
class PLAYย  //class is a keyword and all letters should be lowercase only

//Error 2
int number_of_actors=5;
It should be
int number_of_actors; //one can not give initial values to a data members in a class, as class is just template, it doesn’t have memory space of its own. It gets memory space only when an object is declared based on class. Therefore values can be assigned in class methods only as they will be called only when object is created.


Share

Created: 1-Dec-2018 00:57 | Updated: 22-Mar-2026 20:22|