Woke up this morning, went to work, decided "Free time I'll start coding a bit", so I started messing around with classes. A little background: No matter how much studying, I just can't get the hang of classes and functions. I haven't started making classes separate of the file, just inside the program outside the main function. So, my question is...
What am I doing wrong in declaring my class? I'll list the code and the error.
#include <iostream>
#include <ctime> //Gonna do something with rand();
usingnamespace std;
Class Calc(){
Public:
double add(int x, int y){
double answer = x + y;
return answer;
}
double subt(int x, int y){
double answer = x - y;
return answer;
}
double mult(int x, int y){
double answer = x * y;
return answer;
}
double divide(int x, int y){
double answer = x / y;
return answer;
}
};
int main(){
Calc classObject;
classObject.add(6, 7);
return 0;
}
error I'm getting:
1 2 3 4 5 6
C:\Users\255484\Documents\CodeBlocks\Projects\Calculator\main.cpp|5|error: 'Class' does not name a type|
C:\Users\255484\Documents\CodeBlocks\Projects\Calculator\main.cpp||In function 'int main()':|
C:\Users\255484\Documents\CodeBlocks\Projects\Calculator\main.cpp|27|error: 'Calc' was not declared in this scope|
C:\Users\255484\Documents\CodeBlocks\Projects\Calculator\main.cpp|27|error: expected ';' before 'classObject'|
C:\Users\255484\Documents\CodeBlocks\Projects\Calculator\main.cpp|28|error: 'classObject' was not declared in this scope|
||=== Build finished: 4 errors, 0 warnings (0 minutes, 0 seconds) ===|
This is all really simple coding, I just don't wanna start doing 500+ lines of code as I started to in java, and stop because of a couple errors or frustration. Any help is appreciated.
Really no point to it but to get me more familiar with working with classes. As I said, I've struggled for the longest time with them, and it's frustrating when you've written a ton and you get that error. Simple solution is what I'm seeing from the 1st 2 replies. I should be shot.