C++, error: expected class-name before '{' token

Viewed 125

I have cloned an open source code from github. This project is to be compiled with make which is totally fine. I reconfigured it and created a codeblocks project added its files. I also misplaced some of the files and I did some fixes as well.

My problem is when I compile it, I face with so many errors and the first one is:

error: expected class-name before '{' token

in QProblem.hpp:

#include <qpOASES/QProblemB.hpp>
#include <qpOASES/Constraints.hpp>
#include <qpOASES/ConstraintProduct.hpp>
#include <qpOASES/Matrices.hpp>


BEGIN_NAMESPACE_QPOASES

class QProblem : public QProblemB // error is here
{

while QProblemB has been defined in QProblemB.hpp which is included:

QProblemB.hpp:

#include <qpOASES/Flipper.hpp>
#include <qpOASES/Options.hpp>
#include <qpOASES/Matrices.hpp>


BEGIN_NAMESPACE_QPOASES


class SolutionAnalysis;

class QProblemB
{
    friend class SolutionAnalysis;

    public:
        QProblemB( );

I tried adding

class QProblemB;

However this idea did not work. It leads to another error:

error: invalid use of incomplete type 'class qpOASES::QProblemB'

I could not simplify the source code further. So I uploaded the full project here. The codeblocks project file is inside a folder called codeblocks.


UPDATE

I realized by updating all the files and adding #pragma once in all of them and changing all cpp files to hpp except for the main cpp file, the problem will be fixed. I am still wondering what has been the problem.

0 Answers
Related