function style initializer

Howdy gang,

I'm a student at Virginia Tech and taking a c++ introduction course. I am a complete noob in c++ and programming in general...have had a little bit of experience with matlab which is quite different than c++.

Anyways, when I try to compile my code, I receive the error message "function-style initializer appears to be a function definition"

can someone explain to me what this means?

I set up the function prototypes in main() and then used the function out of the main loop..
Here's an example of one of the errors:



prototype:
double calculateFPS (double obsWeight, double obsK, double gravity, double obsTime);



function call:
void calculateFPS (obsWeight, obsK, gravity, obsTime){

feetperSec = (sqrt(obsWeight/obsK))*tanh(sqrt((gravity*obsK)/(obsWeight/gravity))*obsTime);

return feetperSec;
}

the error occurs where I call the function!


(by the way, this calculates velocity of a skydiver given their weight obsWeight, drag coefficient obsK, gravity, and time of all obsTime.


Thanks for the help
Last edited on
It looks like it's because the return type does not match, double in the prototype void in the implementation. Also the argument list needs to have the variable types. The variable name (not the type) is optional for the prototype, but still recommended for code clarity.

You're also missing the type for the variable feetperSec, you could also just skip that variable and write:
return (complex equation);
Last edited on
Hey thanks a lot rossipoo...but now it will compile with 4 errors saying "uninitialized local variable used - obsWeight"...it has the same error for obsTime , obsK, and feetperSec...not sure why because these variables look like they are initialized to me:

#include <iostream> // for cout, if needed for debugging
#include <fstream> // for file stream support
#include <iomanip> // for formatting support
#include <cmath> // for standard math functions, if needed
#include <string> // for character string type
using namespace std; // put all of that in scope
int main() {

void printTableHeader(ofstream& Log);
void readTableRow (ifstream& Data);
double calculateMass (double obsWeight, double gravity); //mass function prototype
double calculateFPS (double obsWeight, double obsK, double gravity, double obsTime);
double calculateMPH (double feetperSec);
void printTableRow (ofstream& Log, string name, double mass, double obsK,
double obsTime, double feetperSec, double milesperHour);


string obslName; // observed last name of skydiver
string obsfName; // observed first name of skydiver
string name; // outputted full name of skydiver
double obsWeight; // observed weight
double obsK; // observed drag coefficient
double gravity = 32.2; // acceleration of gravity in ft/sec
double feetperSec; // (computed) velocity of skydiver in ft/sec
double obsTime; // observed time of fall



ifstream Data("Input.txt"); // opens the input file
ofstream Log("Output.txt"); // opens the output file


printTableHeader(Log);

Log << fixed << showpoint; //prepares output stream for decimal output

Data.ignore(INT_MAX, '\n'); // skip over first two lines of input
Data.ignore(INT_MAX, '\n');

readTableRow (Data);


while ( Data ) {

name = obsfName + " " + obslName;

calculateMass(obsWeight, gravity);

calculateFPS (obsWeight, obsK, gravity, obsTime);

calculateMPH (feetperSec);

}

readTableRow (Data);



}

btw, not all the lines are commented but its fairly easy to follow
Last edited on
Use [code]your code here[/code] so the indentation is preserved...

Anyway, you are defining them, but not initializing them...

1
2
int x; //declaration
int y = 0; //declaration/initializing 

function call:
void calculateFPS (obsWeight, obsK, gravity, obsTime){

feetperSec = (sqrt(obsWeight/obsK))*tanh(sqrt((gravity*obsK)/(obsWeight/gravity))*obsTime);

return feetperSec;
}


You have not specified the types of the formal parameters.
Topic archived. No new replies allowed.