#include <iostream>
#include <stdio.h>
usingnamespace std;
class Function
{
public:
int Addition(int a, int b)
{
return(a+b);
}
void Print()
{
cout << "Hello! This works.\n";
}
}
int main()
{
int a, b, c;
cout << "Welcome! Fill in a number: ";
cin >> a;
cout << "Fill in another number: ";
cin >> b;
c = Function.Addition(a, b);
printf("The answer is %c.\n", c);
Function.Print();
cout << "Bye bye! Press ENTER to quit.";
cin.get();
return(0);
}
This is my source code, but when i compile it with Dev-C++, it gives this errors:
21 C:\Users\eigenaar\Documents\Eigen bestanden\C++\Source Code\Function_In_Struct.cpp new types may not be defined in a return type
You forgot a semicolon after the class declaration. Also, I hope you know that's not what classes are for, a namespace would be more appropriate. And why are you mixing cout and printf?
He means that classes are not used to group a bunch of functions.
Classes are blueprints for objects, just like in real life you have a plan for a house, and the actual house itself.
Namespaces are used to declare data (like variables or functions) in a specified scope, to avoid mixing names of those variables or functions.
The tutorial on this site has a good explanation (read: better than i could give) on both.