Error from Xcode making no sense to me

Joined
Dec 18, 2009
Messages
5
Reaction score
0
Points
1
Location
Plymouth, England
Your Mac's Specs
15" Unibody MacBook Pro
Hi all, this is a ridiculously simple part of my ridiculously simple program. I have other .h files laid out in an identical way with no errors. However this one get's "expected initializer before int"

#ifndef SUBTRACT_H
#define SUBTRACT_H

int subtract(int x, int y); //error here is "expected intializer before 'int'

#endif

so... what do I do, please?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,745
Reaction score
2,071
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
You do have a semicolon after the function definition?

Regards
 
OP
T
Joined
Dec 18, 2009
Messages
5
Reaction score
0
Points
1
Location
Plymouth, England
Your Mac's Specs
15" Unibody MacBook Pro
You do have a semicolon after the function definition?

Regards

I have done it both with and without. Apologies for the mistake in the first part I posted - I will edit it...
But anyways, the same error comes up regardless.
 
Joined
Dec 13, 2007
Messages
256
Reaction score
10
Points
18
Location
United States of America
Your Mac's Specs
2.1GHz MacBook with 4GB RAM, Mac OS X 10.6, iLife and iWork ‘09
Could you post the code surrounding (mainly above) that? Surround it with
Code:
 blocks if it's longer than a few lines.
 
OP
T
Joined
Dec 18, 2009
Messages
5
Reaction score
0
Points
1
Location
Plymouth, England
Your Mac's Specs
15" Unibody MacBook Pro
Could you post the code surrounding (mainly above) that? Surround it with
Code:
 blocks if it's longer than a few lines.[/QUOTE]

Well that is the code from my header file (subtract.h)

This is the code from main.cpp

[#include <iostream>
#include "Add.h"
#include "Divide.h"
#include "Multiply.h"
#include "Subtract.h"

int main() 
{
	using namespace std;
	cout << "Please enter your first number: " << endl;
	int x;
	cin >> x;
	cout << "Please enter the function you wish to performed: " << endl;
	return 0;
}]

You can see there are other .h files I've made, they all work fine (even though it's not finished) and they're formatted exactly the same as the one I posted above. But for some reason they work and just subtract.h doesn't. Hence my confusion/frustration...
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top