| mendozae (75) | |||||
1. I have this class declared inside a namespace and is in a header file called "date.h" as shown.
2. I have my main in a file called "date.cpp" containing this.
3. When I do this "JuanGilbertoSanchez::date::display();" the compiler complain. the compiler suggest this "&JuanGilbertoSanchez::date::display;" which I did but when I execute it the command is bypassed so nothing is displayed. What am I doing wrong? | |||||
|
|
|||||
| ne555 (4038) | |
| You are trying to call a method without an object. | |
|
|
|
| coder777 (2378) | ||||
& in this case is an address operator. it's not assigned hence nothing happens.As ne555 mentioned you need an object:
| ||||
|
|
||||
| BlackSheep (388) | |||||
&JuanGilbertoSanchez::date::display;will give you the address of the member function. You want to create an object of type date:
And then call the function using that object:
| |||||
|
|
|||||
| kg1992 (30) | |||||
|
Making class is same as making a brand new user-defined "type". Compiler will treat the name of the new class as type name such as "int". Because you have defined "class date" you have new type "date" to use.
Now you have variables, you can call functions. operator+ is 'sort of' function that int type variable can call. display() is function that date type variable can call.
| |||||
|
Last edited on
|
|||||