c++ - Include error.Functions already declared -
i've read lot problem ,but haven't found proper solution. have 4 files:
includes.h - contains libraries need in other files + global functions cities.h - contains declarations of 2 classes cities.cpp - contains definitions of 2 classes in cities.h source.cpp - main functon
and have(and need) these includes
//cities.h #include "includes.h" //cities.cpp #include "cities.h" //source.cpp #include "cities.h"
i've tried combinations of #ifndef
in of files , program continues give me same error: function_x declared in cities.obj
.and error repeats functions in "includes.h". please me.this makes me lot of headaches.
as you've described in comments, have function definitions in includes.h
header file. when included in multiple implementation files, end multiple definitions of functions in program. breaks one definition rule. should declare functions in includes.h
, move definitions includes.cpp
file.
something this:
// includes.h void foo(); int bar(int); // includes.cpp void foo() { // implementation } int bar(int x) { // implementation }
i'm going try , preempt question typically follows answer. no, include guards (#ifndef ...
) not meant prevent this. prevent header being included multiple times in single translation unit. including header in multiple translation units, include guard not stop.
Comments
Post a Comment