Solved

# Problems with returning values, using dereferencing...error C2556 error C2371

Posted on 2003-02-18
Medium Priority
460 Views
I had to write a program for class that requires sending variables by dereferencing, and returning a value through two functions.
I apologize for the lack of documentation.

void ValueF();
double GenerateF(double &NumberV);
double DivideF(double &NumberV, double Divisor);

void Halt();
void ClearS();

void ValueF()
{
double NumberV;
double *NumPtr = &NumberV;
double Manipulated;

ClearS();

cout << "Please enter a number\n\t>";
cin >> *NumPtr;

cout << "\n\n";
cout << "Original:\t" << NumberV << "\n";

//     GenerateF(NumberV);

Manipulated = GenerateF(NumberV);

cout << Manipulated;

return;

}

double GenerateF(double &NumberV)
{
double Divisor;
double *DivPtr = &Divisor;
double Manipulated;

srand(static_cast<unsigned>(time(NULL)));

*DivPtr = (rand() % 10) + 1;

//     DivideF(NumberV, Divisor);

Manipulated = DivideF(NumberV, Divisor);

return(Manipulated);
}

void DivideF(double &NumberV, double Divisor)
{
apvector<double>Quotients(4);
double Manipulated;
int Counter=0;

do{
if(Counter<4)
{
Quotients[Counter] = NumberV / Divisor;
NumberV = NumberV / Divisor;
}
else
{
Manipulated = NumberV / Divisor;
}

Counter++;
}
while (Counter<5);

cout << setw(10) << "Cycle"
<< setw(10) << "Quotient\n\n";

for(Counter=0;Counter<4;Counter++)
{
cout << setw(10) << (Counter + 1)
<< setw(10) << Quotients[Counter];

cout << "\n";
}

NumberV = NumberV / 2;

return(Manipulated);
}

C:\Documents and Settings\TOesterle\Desktop\PtrPractical\ptrpimp.cpp(61) : error C2556: 'void __cdecl DivideF(double &,double)' : overloaded function differs only by return type from 'double __cdecl DivideF(double &,double)'
c:\documents and settings\toesterle\desktop\ptrpractical\ptrphead.h(20) : see declaration of 'DivideF'
C:\Documents and Settings\TOesterle\Desktop\PtrPractical\ptrpimp.cpp(61) : error C2371: 'DivideF' : redefinition; different basic types
c:\documents and settings\toesterle\desktop\ptrpractical\ptrphead.h(20) : see declaration of 'DivideF'
0
Question by:TCOesterle
• 3

LVL 1

Expert Comment

ID: 7978848
So Why fo you keep void DivideF(double &NumberV, double Divisor)
as void if it returns double?
0

LVL 8

Accepted Solution

Exceter earned 300 total points
ID: 7978854
>> double DivideF(double &NumberV, double Divisor);

You declared DivideF as having a return type of double. Yet, you implemented it with a return type of void.

>> void DivideF(double &NumberV, double Divisor)

Even if you had two functions named DivideF this would still generate an error because you are not permitted to overload a function when the only difference between the two is the return type.

Exceter
0

Author Comment

ID: 7978886
Geez, sorry i missed that.  DUMB mistake.
Thanks for the help.
0

LVL 8

Expert Comment

ID: 7978909
You are most welcome.
0

LVL 8

Expert Comment

ID: 7978916
>> DUMB mistake.

That happens to all of us from time to time. :-)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticallâ€¦
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data definâ€¦
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
###### Suggested Courses
Course of the Month12 days, 19 hours left to enroll