c++ - Global function definition -


i'm missing basic.

i want function foo() visible in subroutine in different file.

a\b\c\d\one.cpp

#if xyz   void foo() { ... 

a\two.cpp

void foo(); #if abc    uint8_t top(uint8_ val) {     foo(); 

i not defined errors foo() when two.cpp linked.

a\three.cpp

#if jkl   foo(); 

foo() works fine in three.cpp

there no namespaces.

where going wrong?

i'm missing basic.

for combination of .o files link together, definition of foo() can exists once. (odr) can declared many times needed.

however, choose have single .hh file 'declaration' line:

perhaps "foo.hh" contain

 extern void foo(); // declares foo function 

any .cc file use 'foo' #include .hh file.

and 1 .cc file must implement function body, , should include .hh file.

perhaps "foo.cc" might contain

#include "foo.hh"  void foo() {    // implement  } 

finally, link .o's (from compiling .cc files) main.o.


Comments

Popular posts from this blog

minify - Minimizing css files -

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -