I returned to one of my old C++ school assignments which implemented a binary tree. I have a file (Tree.cpp) that contains functions to insert, lookup, remove, etc nodes. At the top, I have "using namespace std;"
. The warnings I am getting are caused by another file, SymTab.hpp, that looks like this:
#ifndef SYMTAB_H
#define SYMTAB_H
#include <iostream>
#include "Tree.hpp"
using namespace std;
template <class Whatever>
class SymTab : private Tree<Whatever> {
public:
Tree<Whatever> :: Insert;
Tree<Whatever> :: Lookup;
Tree<Whatever> :: Remove;
Tree<Whatever> :: Write;
Tree<Whatever> :: Set_Debug_On;
Tree<Whatever> :: Set_Debug_Off;
};
#endif
Each of the lines after public:
give a warning like:
"SymTab.hpp:11:9: warning: access declarations are deprecated in favour of using-declarations; suggestion: add the ‘using’ keyword [-Wdeprecated] Tree :: Insert;", where "Insert is replaced with each respective function name.
Any advice on namespaces and how to get rid of these warnings?
There's two separate issues. The one the compiler is talking about are the "access declarations" in SymTab
. Simply change it to this:
template <class Whatever>
class SymTab : private Tree<Whatever> {
public:
using Tree<Whatever> :: Insert;
using Tree<Whatever> :: Lookup;
using Tree<Whatever> :: Remove;
using Tree<Whatever> :: Write;
using Tree<Whatever> :: Set_Debug_On;
using Tree<Whatever> :: Set_Debug_Off;
};
The other, totally unrelated issue is using namespace std;
in a header file. That's not an error per se, but a Bad IdeaTM. It causes the entire std
namespace to be dumped into the global namespace for everyone who includes that header and there's nothing they can do about it. And it can lead to wonderful name conflicts with some common names like transform
, list
or sort
which are defined in the std
namespace. Just remove the using
directive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With