You will never see class.method()
or class->method()
in C++. What you will see is object.method()
, obj_ptr->method()
or class::method()
. When you make an object of a class, you use the .
operator, when refering to a pointer to an object, you use ->
and when calling a static method directly without making an object, you use ::
. If you have a class a_class
like below, then:
class a_class
{
public:
void a_method()
{
std::cout<<"Hello world"<<std::endl;
}
static void a_static_method()
{
std::cout<<"Goodbye world"<<endl;
}
}
int main()
{
a_class a_object = a_class();
a_class* a_pointer = new a_class();
a_object.a_method(); //prints "Hello world"
a_object->a_method(); //error
a_object::a_method(); //error
a_pointer.a_method(); //error
a_pointer->a_method(); //prints "Hello world"
a_pointer::a_method(); //error
*a_pointer.a_method(); //prints "Hello world"
*a_pointer->a_method(); //error
*a_pointer::a_method(); //error
a_class.a_method(); //error
a_class->a_method(); //error
a_class::a_method(); //error because a_method is not static
a_class.a_static_method(); //error
a_class->a_static_method(); //error
a_class::a_static_method(); //prints "Goodbye world"
}