unknonw override specifier

I have two class(class a , class b), each contained in different .h and .cpp files. I use inlucde of all .h files in all files. And then I have a class b object in class a(please refer to the code).When I compile the program, error shows - " 'bexa' : unknown override specifier" ; "missing type specifier - int assumed. Note: C++ does not support default-int". Why I am having this problem?
thanks beforehand.

source.cpp
1
2
3
4
5
6
7
8
9
  #include <iostream>
#include "a.h"
#include "b.h"

int main()
{

	return 0;
}


a.h
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once
#include "b.h"

class a
{
public:
	a();
	~a();

	b bexa;
	void function1();
};


a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "a.h"



a::a()
{
}


a::~a()
{
}

void a::function1()
{
	bexa.function1();
}


b.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once
#include "a.h"

class b
{
public:
	b();
	~b();

	void function1();
	void function2();
};


b.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "b.h"



b::b()
{
}


b::~b()
{
}

void b::function1()
{
}

void b::function2()
{
}


b.h should not include a.h, else you end up with a cyclic dependency.
AH..it seems to be the point. THANKS very much!
You can actually put b.h into a.h

Because sometimes if you're working on a project and you have like 5 header files, you forget which is already included. But to do so, you'll need the following syntax:

1
2
3
4
5
6
7
8
9
#ifndef (name of a.h, I prefer it in all caps)
#define (same name, same capslock)

/* class
{
     class code
};  I forget whether or not the semicolon outside the class is necessary or not, I've just put it to make the compiler happy*/

#endif 


Basically that syntax works like an if,then,else. If a certain header file is not defined inside this .cpp or .h or .anything file, define/include it. Otherwise, do nothing.
Last edited on
override is for virtual methods , as for final override to mark a virtual method as sealed.
Topic archived. No new replies allowed.