Frage

When trying to compile my program I get the error

icpc -c main.cpp
main.cpp(4): error: expected a "{"
int main()
^

main.cpp(55): error: return value type does not match the function type
return 0;
       ^

It seems to not be recognizing my main function as the main function. Here is the main function code, Makefile, and header:

main.cpp

#include <iostream>
#include "main.h"

int main()
{
float p,c,dt;
float P[10001], C[10001];

std::cout<<"For the following inputs, the equilibrium values for population and CO2 concentration are 120 and 340 respectively. \nEnter your plant population, p, in 100m^2: ";
std::cin>>p;
std::cout<<"Enter your initial carbon concentration, c, in ppm: ";
std::cin>>c;
std::cout<<"Enter your time interval in number of hours: ";
std::cin>>dt;
dt = 0.01*dt;

co2(c,p,dt,P,C);

int idim,jdim,i1,i2,j1,j2;
idim=100;
jdim=100;
i1=0;
i2=100;
j1=0;
j2=100;
float Clo=0.0;
float Chi=5000.0;

float TR[6] = {0.5,1.,0.,0.5,0.,1.};

plotimage(C,idim,jdim,i1,i2,j1,j2,Clo,Chi,TR);
return 0;
}

Header file:

float dcdt(float, float);
float dpdt(float, float);
void co2(float, float, float, float[], float[]);
void plot(float[], float[], float);
void plotimage(float [],int, int, int, int, int, int, float, float, float [])

Makefile:

main: main.o dcdt.o dpdt.o co2.o plot.o plotmap.o
    icpc -o main main.o dcdt.o dpdt.o co2.o plot.o plotmap.o -ltrapfpe -lpgplot -lcpgplot -lX11 

main.o: main.cpp main.h
    icpc -c main.cpp

dcdt.o: dcdt.cpp main.h
    icpc -c dcdt.cpp

dpdt.o: dpdt.cpp main.h
    icpc -c dpdt.cpp

co2.o: co2.cpp main.h
    icpc -c co2.cpp

plot.o: plot.cpp main.h
    icpc -c plot.cpp

plotmap.o: plotmap.cpp main.h
    icpc -c plotmap.cpp
War es hilfreich?

Lösung

You are missing a semicolon after the last function prototype in your header:

void plotimage(float [],int, int, int, int, int, int, float, float, float []);
//              Here --------------------------------------------------------^

Here is why the compiler tells you that it is looking for an opening curly brace: it sees the last line of the header (which is included verbatim in your main.cpp file) and thinks that it is looking at the beginning of a function definition, not at a forward declaration. It sees the return type, the name, and the list of parameter types, so the next thing that should come after that is an opening curly brace.

Andere Tipps

You missed a semicolon in header file

you have missed using namespace std; after you #include (if you are using MS Visual studio) and you also missed semicolon as mentioned in above answers by Jaguar and dasblinkenlight. That is

 #include<iostream>
 using namespace std;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top