Hello people,
I am new to this community and the only reason for why I joined here is to learn and get all my doubts clarified as I am learning C++ all by myself and also I dont have any computer literate people around me in my place.
I started with the some online and it has been around 2 weeks since I started with C++. I feel as if i understood when read the theory part but when it comes to coding I dont really know where or what am i should be strating with :sad: I just tried writing a small snippet to understand THIS Pointer. First of all, is it called a This pointer or a This operator? I have seen some articles using the term pointer and operator interchangeably to address 'this'.
Here is my snippet: (Please don't laugh at it as I am learning it, It might even be a bluder :-| )
#include <iostream.h>
class A
{
int x;
fn() { return this->x; }
};
void main()
{
A a;
int x=10;
a.fn();
}
It gives me a compilation error stating A::fn()' is not accessible in function main() But why? I did not declare the fn() function as a private. So, should my main function not be having access to the fn() of class A?
I am also recieving a warning like 'x' is assigned a value that is never used Why is this?
Now what should I be doing to make this work? By the way, I am trying to find out the address of the memory which is held by the THIS pointer. I might sound so silly but please bear with me. :rolleyes: