jeudi 16 avril 2020

Weird "classname" has not been declared

container.hpp

#ifndef CONTAINER_HPP
#define CONTAINER_HPP

#include <functional>


namespace lasd {

/* ************************************************************************** */

class Container {

private:

  // ...

protected:

  unsigned long size = 0;

public:

  // Destructor
  virtual ~Container() = default;

  /* ************************************************************************ */

  // Copy assignment
  Container& operator=(const Container&) = delete; // Not usable.

  // Move assignment
  Container& operator=(Container&) = delete; // Not usable.

  /* ************************************************************************ */

  // Comparison operators
  bool operator==(const Container&) const noexcept = delete; // Not usable.
  bool operator!=(const Container&) const noexcept = delete; // Not usable.

  /* ************************************************************************ */

  // Specific member functions

  virtual inline bool Empty() const noexcept;

  virtual inline unsigned long Size() const noexcept;

  virtual void Clear() = 0;

};

#include "container.cpp"

}

#endif

container.cpp

// Specific member functions (Container)


inline unsigned long Container::Size() const noexcept{
  return size;
}

inline bool Container::Empty() const noexcept{
  return size == 0;
}

Give this in output. The funniest part is that all this code is provided by my professor, and I only have coded the .cpp file. I've already tried to add #include "container.hpp" to my .cpp file.

||=== Build: Debug in Exercise1 (compiler: GNU GCC Compiler) ===|
||=== Build: Debug in Exercise1 (compiler: GNU GCC Compiler) ===|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp|4|error: 'Container' has not been declared|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp|4|error: non-member function 'long unsigned int Size()' cannot have cv-qualifier|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp||In function 'long unsigned int Size()':|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp|5|error: 'size' was not declared in this scope|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp|8|error: 'Container' has not been declared|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp|8|error: non-member function 'bool Empty()' cannot have cv-qualifier|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp||In function 'bool Empty()':|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp|9|error: 'size' was not declared in this scope|
C:\Users\Giulia\Desktop\Università\Laboratorio ASD\exercise1\container\container.cpp|38|error: expected initializer before '<' token|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

During professor video lectures, he has compiled the code and it worked so well. I really cannot understand why, by using Code::Blocks, it gives me this error (I've tried on the gpp-compiler on Atom editor too, with the exactly same result).

Thanks.

Aucun commentaire:

Enregistrer un commentaire