Hello everyone. I'm sure this has been asked multiple times and googling I've found plenty of explanations. However, some things just don't come to me unless it's explained with my specific example. I understand that the dot operator is:
"a" is the actual object (not a memory location) and "b" is the member. I also understand the arrow to mean:
"a" is a pointer to a struct and "b" is it's member so "a" is dereferenced then "b" is given.
Here is where I get a little confused. I have a class:
exampleclass.h
Code:
#ifndef EXAMPLECLASS_H_INCLUDED
#define EXAMPLECLASS_H_INCLUDED
class exampleclass{
private:
int number;
public:
exampleclass(); //Constructor
~exampleclass(); //Destructor
void changeNumber(int number);
int getNumber();
};
#endif // EXAMPLECLASS_H_INCLUDED
exampleclass.cpp
Code:
#include "exampleclass.h"
exampleclass::exampleclass(){
this.number = 0;
}
exampleclass::~exampleclass(){
}
void exampleclass::changeNumber(int number){
this.number = number;
}
int exampleclass::getNumber(){
return this.number;
}
and last I have my main client code.
Code:
#include <iostream>
#include "exampleclass.h"
int main(){
exampleclass ec1 = new exampleclass;
//This is where I'm confused. Is ec1 my object
//or is ec1 a pointer to the address of my object
ec1.changeNumber(5); //Is this correct
ec1->changeNumber(9); //or this?
}
Also if ec1 had a public variable and I wanted to access it would it be referenced the same way as the method I call in ec1?