How to get links to namespaced enums to work with Doxygen - c++

I am having trouble getting a link to an enum to work with Doxygen.
With the files below the link of the return value to the Status enum for someFunction works inside the namespace documentation file, but not in the documentation of the test.hpp file.
status.hpp
/// #file
/// my namespace
namespace bla {
/// some enum
enum class Status { Done, Todo };
} // namespace bla
test.hpp
/// #file
#include "status.hpp"
namespace bla {
Status someFunction();
} // namespace bla
file reference
namespace reference

Related

C++ - Use enum from different header file, same namespace

I want to be able to use an enum class that is defined in one file, and used in others. When I try I only get this error: enum "Animal" has no member "Lion"
I can't find any posts that answer my question.
Here is an example of what I have in mind:
zooanimals.h
#pragma once
namespace Zoo
{
enum class Animal;
}
zooanimals.cpp
#include "zooanimals.h"
namespace Zoo
{
enum class Animal
{
Lion,
Elefant,
Monkey
};
}
zoo.h
#pragma once
namespace Zoo
{
class Visitor;
}
zoo.cpp
#include "zoo.h"
#include "zooanimals.h"
namespace Zoo
{
class Visitor
{
Animal favoriteAnimal = Animal::Lion;
};
}
You don't split enums in declaration and definition, so
enum class Animal
{
Lion,
Elefant,
Monkey
};
should be in the header, not in a source file.
Remember, when you include a header into a source file, this source file can only "see" what is declared in this header. In your case, when the compiler processes zoo.cpp, it can not "see" the values of Animal, because they are not in the header.

Include-guards and commented out Doxygen comments affect the output of Doxygen

The behavior of Doxygen 1.8.11 for the following example is really bizarre:
File test.h:
/// \file
/// \namespace N1
/// Namespace N1.
namespace N1 {
#include "a.h"
} // namespace
int main() {
return 0;
}
File a.h:
/// \file
/// \namespace N1::N2
/// Namespace N2
namespace N2 {
#include "b.h"
} // namespace
File b.h:
/// \file
// class A does not appear without the commented Doxygen comments below!
// /// \cond None
#ifndef GUARD
#define GUARD
// /// \endcond
/// Class A
class A {};
// /// \cond None
#endif
// /// \endcond
The class A appears in the documentation of N1::N2 only if the include-guard in b.h is not present or is conditioned out. Interestingly, even having the conditioning comments commented out as in the example suffices to have the class A appear!

Use of "using namespace" when declaring that namespace

Suppose I have the following files:
// SomeClass.h
namespace Example
{
class SomeClass
{
...
SomeClass someFunction();
...
};
}
// SomeClass.cpp
Example::SomeClass Example::SomeClass::SomeFunction()
{
...
}
Would there be any consequences to add "using namespace Example;" before the namespace in SomeClass.h to eliminate the need of adding the "Example::" scope operator to things in the Someclass.cpp file? Even if there are no conesequences, would this be considered bad coding practice?
The change would be as follows:
// SomeClass.h
using namespace Example;
namespace Example
{
class SomeClass
{
...
SomeClass someFunction();
...
};
}
// SomeClass.cpp
SomeClass SomeClass::SomeFunction()
{
...
}
No, please don't put using namespace ...; in the global area. You can just do this:
SomeClass.h
// using namespace Example; // never here please
namespace Example
{
using namespace OtherExample; // this is okay (not global)
class SomeClass
{
...
SomeClass someFunction();
...
};
}
SomeClass.cpp
namespace Example // same as in .h
{
using namespace OtherExample; // this is okay (not global)
SomeClass SomeClass::SomeFunction()
{
...
}
}
And I would also suggest with potentially huge namespaces like std:: to never use using namespace std; even within your own namespaces because they simply drag in too many common symbol names.

conflicting class names in namespace

I have a class which is not part of any namespace
class A(*) .
And I have another class with same name but part of namespace
class A part of namespace B.
In xyz.cpp, I have the below:
#include "..."
using namespace B;
// some code
A::var; // This A should be part of (*) and not namespace B.
// some code
But since I have conflicting class names, I get errors. Is there a way to get around this?
The using namespace keyword imports all of the names from the specified namespace into the global namespace. Since you already declared a class A in the global namespace, this results in a conflict.
Solution: Don't use using namespace B.
This is effectively what you're doing:
namespace GLOBAL {
class A { ... };
};
namespace B {
class A { ... };
};
using namespace B /* export 'B::A' into 'GLOBAL' resulting in a conflict; */ ;
You may not use
using namespace B;
but use like
B::A::var
instead.

C++ namespace issue

I am having three classes all of them are from different namespaces as shown below:
classA.h
namespace outer
{
namespace inner
{
class ClassA
{
....
};
}
}
classB.h
namespace inner
{
class ClassB
{
...
};
}
classC.h
#include <classB.h>
namespace outer
{
namespace inner2
{
using inner::ClassB; // error here, says outer::inner2::ClassB has not been declared.
class ClassC
{
....
};
}
}
I am stuck at this please help me to solve this issue.
You need
using ::inner::ClassB;
because in namespace outer, you have 2 options for inner
::inner - global namespace
::outer::inner - outer namespace
By default, using inner::ClassB; will try to import ClassB from outer::inner.