c++ - What does it mean to declare a variable as a function? -
in example below do
myclass (); i've been told function returns myclass neither of following lines work.
myclass b = a(); a.a = 1; so , can it?
#include "stdafx.h" #include "iostream" using namespace std; class myclass { public: int a; }; int _tmain(int argc, _tchar* argv[]) { myclass (); // function? mean? can a? int exit; cin >> exit; return 0; }
i've been told function returns myclass [...]
that function declaration. declares function called a , makes compiler aware of existence , signature (in case, function takes no arguments , returns object of type myclass). means may provide definition of function later on:
#include "iostream" using namespace std; class myclass { public: int a; }; int _tmain() { myclass (); // *declares* function called "a" takes no // arguments , returns object of type myclass... myclass b = a(); // right, long definition // function a() provided. otherwise, linker // issue undefined reference error. int exit; cin >> exit; return 0; } myclass a() // ...and here definition of function { return myclass(); }
Comments
Post a Comment