So verwenden Sie Std :: Forward richtigC++

Programme in C++. Entwicklerforum
Guest
 So verwenden Sie Std :: Forward richtig

Post by Guest »

Wie verwende ich std::forward richtig? Im folgenden Beispiel habe ich eine Klasse, die ich für std::string nicht instanziieren kann. Was habe ich falsch gemacht?

Code: Select all

class MyClass
{
public:

MyClass() noexcept = default;
MyClass(MyClass &&) noexcept = default;
MyClass(const MyClass &) noexcept = default;
MyClass &operator=(MyClass &&) noexcept = default;
MyClass &operator=(const MyClass &) noexcept = default;

MyClass(const char *MyClass) noexcept :
str(str)
{
}

template 
requires std::is_same::value
MyClass(Type &str) noexcept :
str(std::forward(str))
{
}

// ...

private:

std::string str;
};

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post