"Expression must have class type" error in program

Hi all, I have an assignment to write a program that numerically calculates the integral of a function. The main points of the assignment are to use function overloading, multiple namespaces, and multiple files. So I've made the program and I'm down to just two errors. In the main on lines 32 and 35 it says for noInts "Error: expression must have class type." I've been at this for many hours and can't find a solution to this :(. Included below is the header file, the source file, and the main file. Thanks in advance for the help!

Header:
1
2
3
4
5
6
7
8
#pragma once

class Integration
{
	public:
		double integrate(double A=0, double k=0, double phi=0, double d=0, double a=0, double b=1);
		double integrate(int noIntervals, double A=0, double k=0, double phi=0, double d=0, double a=0, double b=1);
};


Functions file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "IntegrateLib.h"
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

// where function to be integrated goes
double calc(double  x, double  phi, double  k, double  A, double  d){
	return A*sin(k*x + phi) + d;
}

double Integration::integrate(int noIntervals, double A, double k, double phi, double d, double a, double b) {
  vector<double> vecCoeffs(noIntervals+1, 2);
  vecCoeffs[0] = 1;
  vecCoeffs[vecCoeffs.size()-1] = 1;
  vector<double> functionValues(noIntervals+1);
  double intSize = (b - a)/(double)noIntervals;

  for (int i=0;i<=noIntervals;i++){
    double x_i = a + i*intSize;
    functionValues[i] = calc(x_i, phi, k, A, d);
  }
  double multValue = inner_product(vecCoeffs.begin(), vecCoeffs.end(),functionValues.begin(), 0.0);

  return 0.5*intSize*multValue;
}

double Integration::integrate(double A, double k, double b, double phi, double d, double a){
	return ((-1*A*k*cos(k*b + phi) + d) - (-1*A*k*cos(k*a + phi) + d));
}


Main file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "IntegrateLib.h"
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
using namespace std;

int main(){
	double A, k, phi, d, a, b;
	string answer1;
	cout << "Write to file? (yes/no): ";
	cin >> answer1;
	double n;
	cout << "\nOver how many intervals would you like to make the calculation?: ";
	cin >> n;
	cout << "\nPlease specify A: ";
	cin >> A;
	cout << "\nPlease specify k: ";
	cin >> k;
	cout << "\nPlease specify phi: ";
	cin >> phi;
	cout << "\nPlease specify d: ";
	cin >> d;
	cout << "\nPlease specify the lower bound of integration: ";
	cin >> a;
	cout << "\nPlease specify the upper bound of integration: ";
	cin >> b;
	string answer;
	cout << "Exact integration? (yes/no): ";
	cin >> answer;
	Integration noInts();	//z = value of integration
	double z = noInts.integrate(n, A, k, phi, d, a, b);
	cout << "The numerical integration is: " << z;
	if (answer == "yes"){
		double z1 = noInts.integrate(A, k, b, phi, d, a);
		cout << "The exact value of integration is: " << z1;
	}
	if(answer1 == "yes"){
		ofstream newfile("intAnsw.txt");
	newfile << "The numerical integration value with your parameters is: " << z << ".";
	newfile.close();
	}
	
	int f;
	cin >> f;
	return 0;
}
At line 31, you have:

Integration noInts(); //z = value of integration

I believe this may need to be:

Integration noInts; //z = value of integration

This is because the compiler can misinterpret the first line as the declaration of a function.

Look up "most vexing parse" for more info.

Ahh yes you are right, thank you so much! All those hours of time just for a pair of parenthesis... Now it's working nicely, except the numerical integration is returning the wrong value whenever a value for phi is entered. Note that it does return the correct value if phi is set to zero. This seems really strange since phi is only dealt with in the calc function and not the integration function. Any ideas?
I'm no maths expert, so I'm not the person to ask. But one thing springs to mind: presumably, phi is an angle? Are you sure you're using consistent units throughout? IIRC, you need to use radians for the standard maths functions.
Topic archived. No new replies allowed.