I have the following four files,
//struct.h
#pragma once
namespace coffee {
class MD2 {};
class Recorder{};
class Book{};
}
//setup.h
#pragma once
#include "struct.h"
void wire(coffee::MD2 md2, coffee::Book book){}
//strategy.h
#pragma once
#include "struct.h"
#include "setup.h"
namespace strategy {
int wire(coffee::MD2 md2, coffee::Recorder recorder) {}
int setup(coffee::MD2 md2, coffee::Recorder recorder, coffee::Book book) {
wire(md2, recorder);
wire(md2, book); // <--- cant find this function
}
}
//main.cpp
#include <iostream>
#include "strategy.h"
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
There is not using namespace X in header, but the compiler still cant find wire(md2, book), may I please know why?
As noted in comments, the
wirein namespacestrategyshadows thewireincluded from struct.h. Access that function by prepending with::.For instance, the following prints
foorather thanbar::foo: