Hello,
I'm new to C++ and the way to work with classes and header files and so on.
Compiling the following code I get this error (marked in the code):
"expected primary-expression before ']' token
-- main.cpp
-- air.cpp
-- air.h
Now, I've been moving around the definitions etc. between h-files and cpp-files so it's possible the error is related to the way I've structured the whole thing.
I think it's not the array itself that is the issue since I've initiated arrays like that before.
Thanks in advance
// Joakim, Sweden
I'm new to C++ and the way to work with classes and header files and so on.
Compiling the following code I get this error (marked in the code):
"expected primary-expression before ']' token
-- main.cpp
Code:
#include <iostream>
#include "air.h"
using namespace std;
air thisair;
int main() {
thisair.init();
cout << thisair.getDensity(4000, 100) << endl;
while(true) {}
return 0;
}
Code:
#include <iostream>
#include "air.h"
void air::init() {
for (int i=0; i<60; i++) { heightIntervals[i] = 250*i; }
currentDensity = 1.2275;
kValues[] = {lots of values separated by commas in here};
*** ERROR APPEARS FOR THE LINE ABOVE***
}
double air::getDensity(double height, double heightChange) {
for (int i=0; i<59; i++) {
if ((height >= heightIntervals[i]) && (height < heightIntervals[i+1])) {
currentDensity = currentDensity + kValues[i]*heightChange;
}
}
if (height > heightIntervals[59]) { currentDensity = 0; }
return currentDensity;
}
Code:
class air {
double currentDensity;
double heightIntervals[60];
double kValues[60];
public:
void init();
double getDensity(double, double);
};
I think it's not the array itself that is the issue since I've initiated arrays like that before.
Thanks in advance
// Joakim, Sweden
Comment