Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6565511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:06:10+00:00 2026-05-25T14:06:10+00:00

My aim before writing this code was to just practice and learn more about

  • 0

My aim before writing this code was to just practice and learn more about C++ .

The code consists of a class ball which has a ball’s properties like colour , size , weight and also the ‘brand’ and price of the ball .

#include<iostream>
#include<string>
using namespace std;

class ball
{
private:
    int price;                                       //Price of a ball in rupees .
    enum colour { red , green , blue } colour;       // Colour of the ball .
    string brand;                                    // Brand of the ball REEBOK ADIDAS etcetera .
    float size;                                      // Diameter of the ball .
    enum weight { light , medium , heavy }weight;    // Qualitative weight .
public:  

    ball();
    void get_price();
    void get_colour();
    void get_brand();
    void get_size();
    void get_weight();
};

ball::ball() : price(0) , brand(NULL) , size(0.0)
{
    cout<<"In the constructor";
    colour=blue;
    weight=medium;
}

void ball::get_price()
{
    cout<<"In the function get_price()"<<endl<<price<<endl;
}

void ball::get_colour()
{
    cout<<"In the function get_colour()"<<endl<<colour<<endl;
}

void ball::get_brand()
{
    cout<<"In the function get_brand()"<<endl<<brand<<endl;
}

void ball::get_size()
{
    cout<<"In the function get_size()"<<endl<<size<<endl;
}

void ball::get_weight()
{
    cout<<"In the function get_weight()"<<endl<<weight<<endl;
}

int main()
{
    ball glace;
    glace.get_price();
    glace.get_colour();
    glace.get_brand();
    glace.get_size();
    glace.get_weight();
}

The problem came with the usage of enums in class definition .
Initially I got errors like C2436 , C2275 , C2064 . All the errors at each compilation were due to the enum . After fixing them , finally the above code is compilation error free ! But it’s giving me a run-time error . !!

Can anyone explain it to me why ?

PS : I use Microsoft Visual C++ 2005 express edition .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:06:10+00:00Added an answer on May 25, 2026 at 2:06 pm

    You call brand(NULL) on a std::string, that’s the runtime error you are getting. It’s calling the std::string constructor that takes a char const*, to create from a C string, and it can’t be NULL. To construct an empty std::string simply call brand() in your initialization list, or even skip it since if you do the default constructor would be called automatically by the compiler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been asked before, but there is no sample code to be found
I've just joined a team which has been working in a main-always mode for
My ultimate aim is to have an inline div on my page which horizontally
Introduction The Model-View-Controller approach has been in my head since before the holidays and
I'm trying to build binutils 2.21 source code with debugging on. My main aim
I made an APK signed with a certificate which has a validity of 1
I need help understanding how to implement this part of PHP code in Ruby.
I have this code: <p>Hi. I am your friend. you are my friend.<br> we
I aim to try use DevExpress web server controls (which are awesome) in an
My aim is to write an app which generates an char - array (each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.