Error complaining about redeclaration of parameter

Hello,

I am receiving a strange error,
declaration of 'class_friendOverload setClass' shadows a pararmeter

in this member function definition:

1
2
3
4
5
class_friendOverload& class_friendOverload::operator=(class_friendOverload& setClass)
{
    class_friendOverload::class_friendOverload(setClass);
    return *this;
}


If you would like to see the function class_friendOverload::class_friendOverload(const class_friendOverload&), which is my copy constructor, this is what it looks like:

1
2
3
4
5
6
7
8
class_friendOverload::class_friendOverload(const class_friendOverload& setClass)
{
    this->m_value1 = setClass.m_value1;
    for (int i = 0; i < 5; ++i)
    {
        this->m_array1[i] = setClass.m_array1[i];
    }
}
Last edited on
¿which compiler are you using?
class_friendOverload::class_friendOverload(setClass); is invalid and makes no sense.
class_friendOverload& class_friendOverload::operator=(class_friendOverload& setClass)
{
class_friendOverload::class_friendOverload(setClass);
return *this;
}

Though your code has no any sense nevertheless it looks like a compiler bug. In interprets the bolded statement as definition of variable setClass.
@ne555 & vlad from moscow,

I am trying to call the copy constructor. So it is not possible to call any type of constructor, and instead I should have it call something like a Clone() method?
Last edited on
Of course you may try to call the copy constructor, but there is no any sense. Your object is already constructed. In realty in this statement you create a temporary unnamed object that will be destroyed after semicolon.:)

Consider

class_friendOverload obj = class_friendOverload(setClass);


and now remove the left part of the statement. What will you get?
@vlad from moscow,

Nothing/void?
Last edited on
Yes.

class_friendOverload(setClass);

an temporary unnamed object is created and destroyed in the same statement after semicolon.
Topic archived. No new replies allowed.