Class help

Ok, I'm making a calculator and i need help with something. I need my class to access a global variable. Here is my code:

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
// Calculator v1.0.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;
double firstnum;
double secondnum;
char operation;


class Addition
{
	public: 
		int add(firstnum,)
			//got two errors up there^^  it thinks im creating a new type
	private:
}
int _tmain(int argc, _TCHAR* argv[])
{
	cout<<"Welcome to my calculator app!"<<endl;
	cout<<"Input your first number:"<<endl;
	cin>>firstnum;
	cout<<"Now, input your operation: +,*,-";
	cin>>operation;
	return 0;
}



What do I do???
closed account (zb0S216C)
First, initialize those 3 global variables. Uninitialized variables can result in volatile behaviour, which is not what you want.

Second, in the parameter list of Addition::add( ), firstnum must have a type-specifier associated with it. Also, remove the comma and place a semi-colon after the parameter list. Don't forget to provide a body for Addition::add( ).

Before using a class, you must instantiate it. This basically means create an object that is of type Addition. After you've done that, you can invoke the methods of Addition using the dot operator (or member access operator), like so:

1
2
3
4
5
// Instantiate Addition:
Addition NewAddition;

// Invoke Addition::add( ):
NewAddition.add( firstnum );


Wazzak
Last edited on
Topic archived. No new replies allowed.