Help! Output is not printed.

So these are the three files. I executed C.cc, no error is there but nothing gets printed either... It's suppose to print the value of x.
What's wrong in this code, please help!

File A.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include<iostream>

using namespace std;

namespace land
{

class A
{
public:
void SetVal(int a)
{
x=a;
cout<<"Printing x: "<<x;
}

private:
int x;

};

}


File B.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include "A.h"

using namespace std;


namespace land
{

#define VAL 5
class B : public A
{
public:
B()
{
SetVal(VAL);
}


};

}

File C.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include "B.h"

using namespace std;



int main()
{
land::B b1();

return 0;
}


when you have header and source file , make sure to respect the modularity . Declare in header , define in source file . Never using namespace in header . Also #include <iostream> goes in the source file .
The reason is on line 10 in C.cc:

The compiler misinterprets the expression as a declaration of a function b1() that returns an object of type land::B.

Remove the () after b1.
Topic archived. No new replies allowed.