Hi everyone,
Opional read:
At work I am trying to adapt code which I got from the boost website:
http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/example/http/client/async_client.cpp
I'm having major trouble with it but I think a lot of that stems from my inexperience of using classes, I've mostly just done C before this (and not very much of it) so I'm in way over my depth.
The Problem:
I've decided to make a very simple program which involves two classes each calling the other a few times and just outputs a few things so that it's obvious what is happening. Here is my code so far.
a.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#ifndef A_
#define A_
#include <iostream>
#include "b.h"
class class_a
{
public:
//class_a();
void method_a(class_b class_b_object); //error C2061: syntax error : identifier 'class_b'
};
#endif
|
a.cpp
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
|
#include "a.h"
#include "b.h"
void class_a::method_a(class_b class_b_object)
{
::std::cout << "Entered class_a::method_a()" << ::std::endl;
static int i =0;
i++;
if (i<=3){
class_b_object.method_b();
}
::std::cout << "Finished class_a::method_a()" << ::std::endl;
}
int main()
{
::std::cout << "Entered main()" << ::std::endl;
class_a class_a_object;
class_b class_b_object;
class_a_object.method_a(class_b_object);
::std::cout << "Finished main()" << ::std::endl;
return 0;
}
|
b.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#ifndef B_
#define B_
#include <iostream>
#include "a.h"
class class_b
{
public:
// class_b();
void method_b(class_a class_a_object); //error C2061: syntax error : identifier 'class_a'
};
#endif
|
b.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include "b.h"
#include "a.h"
void class_b::method_b()
{ //error C2511: 'void class_b::method_b(void)' : overloaded member function not found in 'class_b'
::std::cout << "Entered class_b::method_b()" << ::std::endl;
static int i =0;
i++;
if (i<=3){
class_a_object.method_a(class_a_object;);
}
::std::cout << "Finished class_b::method_b()" << ::std::endl;
}
|
I am getting this error from visual studio:
syntax error : missing ';' before '.' |
I've marked on the code where it says this error occurs.
If someone could tell me how to fix this error that would be great. If they could tell me whether or not I'm going about this whole thing the correct way that would be even better.
Thanks for your time,
Meerkat
EDIT: just to let you know, I had tried
class_b.method_b();
both with and without (), and I get the same error. Having another look at the code though, I think () shouldn't be there.