A few things. First, in your definition of int DumbBell::setWeight(int) you are casting the member variable to an int and setting it equal to w. Member variable weight is already declared as an int in the class DumbBell, so you shouldn't cast it. Second, this member function is expected to return an int. You probably should make it void. Third, you are trying to cout bar.setWeight(). setWeight(int) needs to take an int argument. You can't call it with a void as you are here. You should write an accessor member function called something like int getWeight() for your class and just have it return weight. One last thing, you might also want to write a ctor for the class that initializes weight to 0 or something so if someone tries to call getWeight() before they use setWeight(int), it won't return some random garbage value.
#include<iostream>
usingnamespace std;
class DumbBell
{
int weight;
public:
void setWeight(int);
int getWeight(int) {return (weight);} //Why does this function take a parameter - it is not used
};
void DumbBell :: setWeight(int w)
{
weight = w;
}
int main()
{
DumbBell bar;
bar.setWeight (200);
cout << "The weight is " << bar.getWeight(int) << endl; // bar.getWeight(int) - this is not the correct way to call a function anyway
system("pause");
return 0;
}//invoice.cpp
when you try to initialize a class, you always call the constructor as default, and the paremeters you are trying to pass is to a constructor that doesn't exist ;)
as far as i can see from the error, it is trying to call the constructor that does not have any paremeters, however your constructor does. you could use constructor overloading. having multiple constructors with different paremeters.