Unused parameter Warning in Polymorphism

I'm trying to eliminate Warning: Unused parameter.

Shape has 4 parameters.

 
 Shape(float a, float b, float c, bool v)


I keep putting 0, but I get the warning when I do that.

 
Rectangle::Rectangle(float len, float wid, bool ver): Shape(length_, width_, 0, verbose_)
Remove the name of the parameters that you don't use, or put them in comments.
Shape is used for other class-es. If I comment them out, it will mess up my parameters for the other class-es.
For example, If you don't use ver inside the Rectangle constructor you can either remove the name (if you don't use it you don't need it)

 
Rectangle::Rectangle(float len, float wid, bool) ...

Or, if you still want the name because it describes what the parameter is about, you could just put the name in a comment.

 
Rectangle::Rectangle(float len, float wid, bool /* ver */) ...


The last alternative is of course to disable the warning, if you don't agree with the practice of having to do it like this. That might however increase the chances of making mistakes. The good thing about this warning is that it let's you know if you forget to use a parameter, or accidentally use another variable when you meant to use a parameter.
Last edited on
How would I comment it out for

Shape(length_, width_, 0, verbose_)

I included the 0 because when I don't include it, I get an error for not using the same expected arguments.
The warning is about the parameters, not the arguments. Which function (the Rectangle constructor or the Shape constructor?) and which parameters is it complaining about?
Last edited on
I have a class Shape, and it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Shape
{
public:
  Shape();
  Shape(float x, float y, float z, bool v);
virtual ~Shape();
  virtual const char* Name() const;
  virtual float Volume() const;
  virtual float Area() const;

protected:
  float x_, y_, z_;
  bool verbose_ = 0;

};


My Rectangle class looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Rectangle : public Shape
{
public:
  Rectangle();
  Rectangle(float l, float w, bool v);
 virtual ~Rectangle();
  const char* Name() const;
  float Area() const;

protected:
  float length_;
  float width_;
  bool verbose_ = 0;
  Rectangle (const Rectangle&);
  Rectangle& operator= (const Rectangle&);
};


I get the unused parameter warning when implementing my constructor:

 
Rectangle::Rectangle(float len, float wid, bool ver): Shape(length_, width_, 0, verbose_)

It is because you don't use the parameters len, wid and ver. Instead you pass the uninitialized members length_, width_, and verbose_ to the Shape constructor.

You probably meant to do something like this:
1
2
3
4
5
6
7
Rectangle::Rectangle(float len, float wid, bool ver)
:	Shape(len, wid, 0, ver),
	length_(len),
	width_(wid),
	verbose_(ver)
{
}
Last edited on
Thank you. That's exactly what I needed.
Topic archived. No new replies allowed.