?
Solved

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

Posted on 2003-02-18
5
Medium Priority
?
427 Views
Last Modified: 2008-02-26
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.
Please help me!

All headers included in ptrphead.h.

#include "ptrphead.h"

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
Comment
Question by:TCOesterle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Expert Comment

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

Accepted Solution

by:
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

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

Expert Comment

by:Exceter
ID: 7978909
You are most welcome.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 7978916
>> DUMB mistake.

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question