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

  • SEARCH
  • Home
  • 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 8338523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:36:53+00:00 2026-06-09T04:36:53+00:00

The problem i’m having is with the string parameter. I’m not exactly sure how

  • 0

The problem i’m having is with the string parameter. I’m not exactly sure how to use it. I just want classification to have undefined length string from the onset until entered by user. The error i’m getting is declaration of ‘std::string classification’ shadows a parameter when i type string classification. What is the correct way to pass the string argument to class members?


#include <iostream>
#include <string>
#include <iomanip>

using namespace std;


class Shapes 
{ //Begin Class Definition
      private:


       float side;
       float height;
       int exponent;
       string *classification;




      public:

             Shapes(float side, float height, string * classification);
             //CONSTRUCTOR
             ~Shapes(){};
             //DESTRUCTOR

      float area(float side, float height, string *classification);
      float perimeter(float side, float height, string *classification);




}; // End Class Definition



int power(float side, int exponent)

{
     int i;
     int total[exponent];
     float sum;

     for ( i = 0 ; i < exponent ; i ++ )
     {
      total[i]= side;
      sum *= total[i] ;

     }

     return sum;

}


float Shapes::area(float side, float height, string *classification)

{
     float area=0.0;
    string classification;
     getline(cin,string);

    if (classification == "square" ) 
    {

              area = power(side,2);
              return area;


    } 

      if (classification == "triangle" ) 
    {
         area = (side* height) / 2 ;
         return area;

    } 

      if (classification == "hexagon" ) 
    {
         float constant = 2.598706;

         area= constant * power(side,2);
         return area;

    } 


      if (classification == "circle" ) 
    {

    } 

};
  • 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-06-09T04:36:54+00:00Added an answer on June 9, 2026 at 4:36 am

    You are redeclaring the string named classification. You only have to declare that variable in the class declaration once for it to be used in all your member functions. You are also using the same name for your arguments which is confusing and dangerous.

    You should also be careful what you are doing with pointers here, it seems like you’re not exactly sure when to use them, or use references. If you indeed tried to compare your string* classification argument like this, if (classification == "triangle" ), you would realise that you can’t compare std::string* to const char*

    Ideally, you should be using enumerations here, like so.

    class Shape
    {
      public:
        enum Classification { SQUARE, TRIANGLE, CIRCLE };
    }
    
    Shape::Area(float side, float height, Classification shapeClass)
    {
      if(shapeClass == SQUARE) {} // Etc
    }
    

    Even better than that you would be using inheritence and polymorphism and overloading functions like area()

    class Shape { virtual float Area(); };
    class Triangle : public Shape { virtual float Area(); };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem description I have 6 databases from 6 different machines, and having one cloud
Problem I have a one time use object which is a composite of several
Problem: I have a table that prints out vertical but I would like it
Problem: I have two array where one produce a category and the second produce
Problem Using Director 11.5 and Windows 7, with MouseWheel Xtra (wheelmouse.zip), I have the
Problem: I can set the exposureMode property of AVCaptureDevice, but it does not stay
Problem Description: We have a service which has applications for main mobile OS’s. We
Problem! I Have the following input (rules) from a flat file (talking about numeric
Problem PHP session in different folder. I have problem with PHP session. There are
Problem statement: I want to upload a large binary (such as an audio clip)

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.