Hello, I made a program that worked perfectly on one of my pcs. When I moved it to another computer I am getting an error now stating that I need to include a pointer on my fmin and fmax functions. I'ts somewhat lengthy but I want to know if maybe te requirement for the pointer might be because of something else in my code. If you can explain why I need to use pointers only for fmin and fmax if its necessary that would be great.

calc.h

#pragma once
class calc
{
private:
    int Size;
    float sum;
    int x;
    float mAx;
    float mIn;
    float mult;
    float var;
    float stdev;
    float sub;
    float valArr[100];
    float avg;
public:
    calc();
    void calculations();
    void outputs();
    bool cont(char choice);
    void difference();
    float fmax(float valArr[],int Size);
    float fmin(float valArr[],int Size);
};

calc.cpp

#include "calc.h"
#include <cfloat>
#include <iostream>
#include <climits>
#include <cmath>
calc::calc()
{
    std::cout<<"Please Input Your Values"<<std::endl;
    std::cout<<"Up To 100 Values"<<std::endl;
    std::cout<<"Type 0 When Ready To Calculate"<<std::endl;
}


void calc::calculations()
{
    for (x=0;x<Size;x++)
    {
    std::cin>>valArr[x];
        if(valArr[x]==0)
        {
            break;
        }
    sum+=valArr[x];
    difference();
    mult*=valArr[x];
    fmax(valArr,x);
    fmin(valArr,x);
    }
    avg = sum/x;
       for ( int i=0; i<x; i++)
    {
        var += (valArr[i] - avg) * (valArr[i] - avg);
    }
    var /= x-1;
    float stdev = sqrt(var);
}

float calc::fmax(float valArr[],int Size)//here is where the error occurs
{
    mAx = valArr[0];
    for (int x=1; x<Size;x++)
    {
        if (valArr[x]>mAx)
            mAx=valArr[x];
    }
    return mAx;
}
float calc::fmin(float valArr[],int Size) //here is where the error occurs
{
     mIn = valArr[0];
    for (int x=1; x<Size;x++)
    {
        if (valArr[x]<mIn)
            mIn=valArr[x];
    }
    return mIn;
}

void calc::outputs()
{
    std::cout<<"Sum of the values are: "<<sum<<std::endl;
    std::cout<<"The Difference of the Values are: "<<sub<<std::endl;
    std::cout<<"Mult equals: "<<mult<<std::endl;
    std::cout<<"Minimum Value: "<<fmin<<std::endl;
    std::cout<<"Maxmimum Value: "<<fmax<<std::endl;
    std::cout<<"The Average is: "<<avg<<std::endl;
    std::cout<<"Variance (pop) is: "<<var<<std::endl;
    std::cout<<"Standard Deviation(pop) is: "<<stdev<<std::endl;
    std::cout<<std::endl;
    std::cout<<"Do You Need To Enter In A New Set Of Values? (Y/N): "<<std::endl;
}

bool calc::cont(char choice)
{

std::cin>>choice;
if (choice=='y'||choice=='Y')
{
    return true;
}
else
{
    return false;
}
}
void calc::difference()
{
    if (x==0)
    {
        sub=valArr[0];
    }
    else
    {
        sub-=valArr[x];
    }
}

main.cpp

#include "calc.h"
#include <cfloat>
#include <iostream>
#include <climits>
#include <cmath>
#include <cstdio>
int main()
{
    calc start;

    do 
    {
        start.calculations();
        start.outputs();


    }while(start.cont(true));
}

error:
calc::fmin': function call missing argument list; use '&calc::fmin' to create a pointer to member

and when I try that this pops up:
'float &calc::fmax(float [],int)' : overloaded function differs only by return type from 'float calc::fmax(float [],int)'
1>calc.h(22) : see declaration of 'calc::fmax'
calc.cpp(39): error C2040: 'calc::fmax' : 'float &(float [],int)' differs in levels of indirection from 'float (float [],int)'

Again thank you for taking time to read.

Recommended Answers

All 7 Replies

I'm wondering if the problem is in using a different compiler or diffferent compiler settings.

So with how I have my code setup, is it a requirement that I have a pointer to make fmin and fmax work?

It looks like you're calling fmin anf fmax without supplying any arguments and the compiler can't find the overload for that. That's why it's asking for a pointer. I suspect the compiler on the other pc was more forgiving in this regard. In my VC++ 2010, it suggests using &calc::fmin. This allows it to compile and run. However I'm not sure that it does what you expect it to do.

Wouldn't the arrVal and x be the arguments? Also for some reason the code for fmin and fmax are turning arrVal[] into.

float calc::fmax(*arrVal[],Size)
float calc::fmax(*arrVal[],Size)

By making these changes I got your code to work. You weren't setting Size anywhere that I could find, so I set it to x in the opening loop.

for (x=0; x<Size; x++)
{
    std::cin>>valArr[x];
    if(valArr[x]==0)
    {
        Size = x;
        break;
    }

    sum+=valArr[x];
    difference();
    mult*=valArr[x];
    fmax(valArr,x);
    fmin(valArr,x);
}    

Then passing ValArr and Size like this seems to work

std::cout<<"Minimum Value: "<<fmin(valArr,Size)<<std::endl;
std::cout<<"Maxmimum Value: "<<fmax(valArr,Size)<<std::endl;

I'm using Code::Blocks and GNU GCC

blah didnt realize I copied and pasted my comparison one basically a backup of one i have incase i forget to save and make a big error... But it is still spitting out that stupid error of the & pointer gonna try installing code::blocks on this pc and see if it still gives me the error

it seems to work on code::blocks perfectly... and i just set Size to =100 in calculations() somehow fixed the bug on visual studious.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.