rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.12k stars 430 forks source link

'make_unique' no matching overloaded function found #292

Closed paulhazen closed 3 years ago

paulhazen commented 3 years ago

Hello, I'm trying to get started with RTTR, but have hit a wall.

Here is an example I wrote to show the problem I am having, I'm hoping someone can point me to what I'm doing wrong.

SerializationTest.h:

#pragma once
#include <string>
#include <stdlib.h>
#include <rttr/registration>

class SerializationTest
{
public:
  SerializationTest() : numberValue(rand() % 100), stringValue("blah blah blah") {};
  SerializationTest(const std::string& name) : SerializationTest() {};
  int numberValue;
  std::string stringValue;
  RTTR_ENABLE()
};

SerializationTest.cpp:

#include "SerializationTest.h"
#include <rttr/type>

RTTR_REGISTRATION
{
  rttr::registration::class_<SerializationTest>("SerializationTest")
  .constructor<std::string>()
  .constructor<>()
  .property("numberValue", &SerializationTest::numberValue)
  .property("stringValue", &SerializationTest::stringValue);
}

Running this causes the following to happen:

...\bind_impl.h(353,28): error C2672: 'make_unique': no matching overloaded function found
...\bind_impl.h(358,1): error C2784: '_Unique_if<T>::_Single_object rttr::detail::make_unique(Args &&...)': could not deduce template argument for 'Args &&' from 'overloaded-function'

I can't for the life of me figure out what's going wrong. Can someone point out what stupid thing I'm doing?

paulhazen commented 3 years ago

Okay, here's what I did wrong, in case anyone else has this issue:

When I was getting started with RTTR I ran into this issue at compile time:

'get': use of dependent template name must be prefixed with 'template'

That caused me to find issue #183. The originating text of that issue says that changing the code in bind_impl.h to use the 'template' prefix will silent the issue. It's true that it will silence the issue, but it will also apparently cause this error in the code at compile time.

In order to fix the issue I returned bind_impl.h to it's 0.9.6 release, and instead of fixing the build issue with prefixing 'template', I went to Project Settings > Configuration Properties > C/C++ > Language > and set Conformance mode from yes /permissive- to No

paulhazen commented 3 years ago

I should add that it's been pointed out to me that an additional problem with my example is that because my constructor is SerializationTest(const std::string& name), the constructor binding needs to look like this: .constructor<const std::string&>()