Skip to content

Not working for classes containing "_declspec(dllimport)" in their declaration #1108

Description

@shikhartanwar

Hi,

I have a 3rd party SDK included in my project that has class declarations like below -
Let's assume the class name as Person (simplified the code for reporting purposes) -

class _declspec(dllimport) Person 
{
       public std::string name;
}

I am trying to serialize the class using the below to_json function as mentioned in the documentation -

#include <Person.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
void to_json(json& j, Person & o)
{
	j = json{ { "value", o.name } };
}

Person p = new Person();
p.name = "Test";
json j = p;

However even though everything is syntactically correct, I am getting the below errors on building my project -

  1. could not find to_json() method in T's namespace
  2. 'force_msvc_stacktrace': is not a member of 'Person'
  3. 'force_msvc_stacktrace': undeclared identifier
  4. forcing MSVC stacktrace to show which T we're talking about.

I have also tried creating a simple class without the _declspec(dllimport) and that works like a charm.

Can someone please help in this regard?

Details:

  1. Compiler: Visual Studio 2017
  2. Operating System: Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions