I've been trying to learn how to declare functions inside a class in CPP:
This is the program I wrote:
//Passing object as function arguments and returning objects
#include <iostream>
using namespace std;
class item{ //Function can be declared either within the class (in that case, there is no need of making the data private)
int price;
float cost;
public:
int newFunction(item a){
a.cost=10;
a.price=40;
return a.cost;
}
} obj1;
int main(){
cout << item::newFunction(obj1);
return 0;
}
Can someone tell why does the compiler give error "a nonstatic member reference must be relative to a specific object".
Also, can someone tell the difference between :: (scope resolution operator) and accessing class elements using .(dot operator). I am sort of confused between the two, and Googling the difference didn't bring any matchable results.