Friday, 15 June 2012

c++ - Access declarations are deprecated in favor of using-declarations; suggestion: add the ‘using’ keyword -



c++ - Access declarations are deprecated in favor of using-declarations; suggestion: add the ‘using’ keyword -

i returned 1 of old c++ school assignments implemented binary tree. have file (tree.cpp) contains functions insert, lookup, remove, etc nodes. @ top, have "using namespace std;". warnings getting caused file, symtab.hpp, looks 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 lines after public: give warning like:

"symtab.hpp:11:9: warning: access declarations deprecated in favour of using-declarations; suggestion: add together ‘using’ keyword [-wdeprecated] tree :: insert;", "insert replaced each respective function name.

any advice on namespaces , how rid of these warnings?

there's 2 separate issues. 1 compiler talking "access declarations" in symtab. alter 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 using namespace std; in header file. that's not error per se, bad ideatm. causes entire std namespace dumped global namespace includes header , there's nothing can it. , can lead wonderful name conflicts mutual names transform, list or sort defined in std namespace. remove using directive.

c++ tree namespaces binary

No comments:

Post a Comment