0

code

   category::category ( const std::string p_name , std::string p_ImagePath) :
    m_name { p_name },
    m_ImagePath {p_ImagePath }
    {

    }

header

#pragma once
#include <string>
class category
{
public:
    const int i;
    explicit category ( const std::string p_name ,const std::string p_ImagePath);
    ~category ( );
    std::string GetName ( );
private:
    std::string m_name;
    std::string m_ImagePath;
};

I allways get errors due to assignment opperator

Fehler 1 error C2280: 'booking &booking::operator =(const booking &)' : attempting to reference a deleted function C:\Program Files (x86)\Microsoft Visual C++ Compiler Nov 2013 CTP\include\utility 53

if i try to use a const member variable or a const static member variable in a class.

I tried const i = 5;
static const i = 5;
and const i; -> i gets initialized in constructor.

Nothing works, how can i fix this? And i cant use constexpr due to vs2013 does not assist it :(

I already checked some questions on Stackoverflow but everything was with constexpr

user3718058
  • 303
  • 1
  • 3
  • 11

1 Answers1

2

You have to define the copy assignment operator explicitly. As your class has a const, non-static data member then the compiler defined copy assignment operator is deleted.

Also it is totally unclear what is the meaning of that const, non-static data member in your class definition.

As for the constructor, you may remove function specifier explicit and define the parameters as constant references.

category( const std::string &p_name, const std::string &p_ImagePath );
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335