#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    90
    Rep Power
    12

    Problems with function


    error C2556: 'void __cdecl null(float,float,float)' : overloaded function differs only by return type from 'float __cdecl null(float,float,float)'
    7) : see declaration of 'null'

    (23) : error C2371: 'null' : redefinition; different basic types

    Code:
    #include <iostream>
    using namespace std;
    float null( float a, float b, float c);
    
    void main()
    {
    	int h,b,product,art;
    
    	h=5;
    	b=3.5;
    	product=0;
    	null(h, b, product);
    	art=product/2;
    	cout<<"area:"<<art;
    	return;
    }
    
    void null( float a, float b, float c)
    {
    	c=a*b;
    	return;
    }
    *edit: placed code tags
    *note: start using code tags around your code samples
    Last edited by Onslaught; October 6th, 2003 at 10:25 PM.
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    you cant call your function null.
    wait lol
    .no, you implement it different then u declared it. it returns a float.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    90
    Rep Power
    12
    hmmm...can you specify where?
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,272
    Rep Power
    2222
    Compare the function prototype at the top of the file with the function header where you actually define the function. They need to be identical (except for the semicolon, of course). Because the second one is different from the first, the compiler is complaining that it has been redefined.

    Now, if you still want to return the value through the third argument (float c), then you need to make it a reference. Otherwise you will never get the answer from that function. And be sure to put that change in both the function prototype AND the function header (you've got to keep them identical).

IMN logo majestic logo threadwatch logo seochat tools logo