I am new to C ++, but I have some experience working in Java. During coding, I came across an error that confused me. Here is my code (simplified, but the errors are the same):
hijras:
#pragma once #include "Bh" class A { public: A(); void foo(); void sayHello(); B b; };
a.cpp:
#include "Ah"
Bh:
#pragma once #include "Ah" class B { public: B(); void bar(A *a); };
B.cpp:
I want to pass an object pointer to a bar function in B so that I can modify and access fields in a string. Oddly enough, I get these errors when I call foo through instance A from another class:
1>------ Build started: Project: Test, Configuration: Debug Win32 ------ 1> main.cpp 1>d:\stuff\visual studio 2015\projects\test\test\bh(7): error C2061: syntax error: identifier 'A' 1> B.cpp 1>d:\stuff\visual studio 2015\projects\test\test\ah(9): error C3646: 'b': unknown override specifier 1>d:\stuff\visual studio 2015\projects\test\test\ah(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1> A.cpp 1>d:\stuff\visual studio 2015\projects\test\test\bh(7): error C2061: syntax error: identifier 'A' 1>d:\stuff\visual studio 2015\projects\test\test\a.cpp(5): error C2660: 'B::bar': function does not take 1 arguments 1> Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The code works fine if I don't include Ah in Bh and I don't pass anything to the bar function.
I tried to understand what could cause these errors, but I could not solve the problem myself, because I do not understand what causes these errors. What am I doing wrong?
mrlux source share