'Namespace confusion: No declaration matches 'namespace::object::function'
I befriended a constructor of a class priv by referencing it with the priv::-scope resolution from another class (notices), thinking that it would find the class object which resided in the same namespace. Turns out it doesnt and yelds a couple of other errors. What am I missing?
Errors:
In file included from C:/dev/test-cpp/components/fsm/include/notices.hpp:3,
from C:\dev\test-cpp\components\fsm\fsm.cpp:1:
C:/dev/test-cpp/components/fsm/include/priv.hpp:11:20: error: 'notices' does not name a type
11 | priv(const notices&);
| ^~~~~~~
C:\dev\test-cpp\components\fsm\fsm.cpp:31:5: error: no declaration matches 'fsm::priv::priv(const fsm::notices&)'
31 | priv::priv(const notices& nos)
| ^~~~
In file included from C:/dev/test-cpp/components/fsm/include/notices.hpp:3,
from C:\dev\test-cpp\components\fsm\fsm.cpp:1:
C:/dev/test-cpp/components/fsm/include/priv.hpp:8:11: note: candidates are: 'constexpr fsm::priv::priv(fsm::priv&&)'
8 | class priv
| ^~~~
C:/dev/test-cpp/components/fsm/include/priv.hpp:8:11: note: 'constexpr fsm::priv::priv(const fsm::priv&)'
C:/dev/test-cpp/components/fsm/include/priv.hpp:11:9: note: 'fsm::priv::priv(const int&)'
11 | priv(const notices&);
| ^~~~
C:/dev/test-cpp/components/fsm/include/priv.hpp:8:11: note: 'class fsm::priv' defined here
8 | class priv
| ^~~~
mingw32-make[2]: *** [components\fsm\CMakeFiles\fsm.dir\build.make:76: components/fsm/CMakeFiles/fsm.dir/fsm.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:897: components/fsm/CMakeFiles/fsm.dir/all] Error 2
mingw32-make: *** [Makefile:120: all] Error 2
fsm.cpp:
#include "notices.hpp"
#include "priv.hpp"
#include "states.hpp"
namespace fsm {
/* definition of class notices */
notices::notices()
{
// reserve as many bits as needed
states_to_set = new uint32_t[STATE_MAX_STATES / 32 + (STATE_MAX_STATES % 32 > 0)]();
states_to_clear = new uint32_t[STATE_MAX_STATES / 32 + (STATE_MAX_STATES % 32 > 0)]();
}
/* definition of class priv */
priv::priv(const notices& nos)
{
printf("sending out notices to %d", nos.states_to_set, nos.states_to_clear);
}
}
notices.hpp
#pragma once
#include "priv.hpp"
#include "states.hpp"
#include <cstdint>
namespace fsm{
class notices
{
public:
notices();
private:
friend priv(const notices&);
uint32_t* states_to_set;
uint32_t* states_to_clear;
};
}
priv.hpp
#pragma once
#include "notices.hpp"
namespace fsm {
class priv
{
public:
priv(const notices&);
};
}
states.hpp
#pragma once
enum global_states_t {
STATE_SOME_STATE_A = 0,
STATE_SOME_STATE_B,
STATE_MAX_STATES,
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
