Why does my class return not 0?
Hello!
I'm currently studying classes.
And so far I got the hang of it.
But I started to experiment somethings and one of those things is this code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
// array of structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class vaas
{
int niko;
public:
vaas()
{
niko=0;
}
};
int main ()
{
//int a;
vaas john();
cout<<john;
//cout<<vaas.age;
}
|
my question is why does it output 1 instead of 0?
Thank you for your time and answers :)!
1 2 3
|
void john();
int john();
std::string john();
|
those are function declarations, then it is expected that
vaas john();
would also be a function declaration.
To create an object using the default constructor write
vaas john;
, note the lack of parenthesis, or
vaas john{};
, with curly braces.
Then you'll have a compile error on
cout<<john;
as you never especified how a `vaas' may be print to screen.
Last edited on
Topic archived. No new replies allowed.