Closed takuto2835 closed 3 years ago
Could you please provide how you use the function_t ? One example is part of CI and I wonder why I haven't seen this issue (still it can be a bug).
I just copied and pasted a part of simple.cc directly into the beginning of my app. It seems that this C2248 is occurring at the point corresponding to "Solver solver;" in line 63 of simple.cc.
I looked into it and it seems to be a factor of the Visual Studio 2019 compiler.
https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=msvc-160
Initializers for inline static data members Invalid member accesses within inline and static constexpr initializers are now correctly detected. The following example compiles without error in Visual Studio 2017, but in Visual Studio 2019 under /std:c++17 mode it raises error C2248:
struct X
{
private:
static inline const int c = 1000;
};
struct Y : X
{
static inline int d = c; // VS2019 C2248: cannot access private member declared in class 'X'.
};
To avoid the error, declare the member X::c as protected:
struct X
{
protected:
static inline const int c = 1000;
};
Fixed in #135
I tried to utilize the solver in my application, but I got error C2248. The error was 'cppoptlib::function::Function<double,-1>::Dim': unable to access private member. I don't know if this is the right way to do it, but I changed "private:" to "public:" in line 60 of "function.h" and the error disappeared.