Drawbacks when including Header in HPP file? Visual Studio Code code completion broken for HPP files
Current behavior
When editing *.hpp
files, code completion and other features are broken, because Visual Studio Code does not know about the files included in the corresponding *.h
file.
Expected behavior
Visual Studio Code automatically resolves all types known to the corresponding .h
file.
Steps to reproduce
Create a *.hpp
file not including its *.h
file.
Question
When creating a cyclic dependency that is including the *.h
file in the *.hpp
file I can use the code completion provided by the LSP server.
Are there any drawbacks when using this? It is of course necessary to have proper include guards and include the files on the correct positions. I have attached an example.
The *.h
file
#pragma once
#include "plugins/structure/tModule.h"
namespace finroc::dennis_experiments::hpp_tests
{
/**
* This example provides an HPP file that is including the header file.
* So we have a cyclic dependency. Is this compilable?
*/
class mHppIndexingExample : public structure::tModule
{
public:
mHppIndexingExample(core::tFrameworkElement *parent, const std::string &name = "HppIndexingExample");
protected:
/** Destructor
*
* The destructor of modules is declared protected to avoid accidental deletion. Deleting
* modules is already handled by the framework.
*/
virtual ~mHppIndexingExample();
private:
virtual void Update() override;
};
}
#include "mHppIndexingExample.hpp"
The *.hpp
file
#include "mHppIndexingExample.h"
namespace finroc::dennis_experiments::hpp_tests
{
mHppIndexingExample::mHppIndexingExample(core::tFrameworkElement *parent, const std::string &name) :
tModule(parent, name, false)
{
// NOOP
}
mHppIndexingExample::~mHppIndexingExample()
{
// NOOP
}
void mHppIndexingExample::Update()
{
// NOOP
}
}