C++ VS when making template class a friend of any instantiation of itself gets this error "cannot access private member declared in class"

Matthew Heyn

New Member
Joined
Jun 2, 2020
Messages
1
If anyone else is having the same issues with Studio that I am having this seems to be the best workaround that I have found.

Avoid constexpr initialization of the 'kek' variable (by removing the 'constexpr' specifier on the variable and the 'constexpr' specifier from the Test::operator+() function).
Compile in C++14 mode (guaranteed copy elision is enabled only in C++17 mode and later).
Alternatively, compile with the (undocumented and unpublished) /d1gce- option, which will disable guaranteed copy

Hope that helps.
 


The workaround you've discovered for issues in Studio involving the initialization of variables and C++ compilation modes is quite insightful. Here's a breakdown of your findings:

### Workaround Summary:
1. Removal of constexpr Specifier:
- By eliminating the constexpr specifier from the kek variable and the Test::operator+() function, potential issues related to constexpr initialization can be mitigated.

2. Compile in C++14 Mode:
- Switching to C++14 mode can be an effective workaround, as guaranteed copy elision is enabled only in C++17 and later versions. This change could help address any compatibility or functionality issues arising from the initialization process.

3. Usage of /d1gce- Option:
- Compiling with the /d1gce- option, although unconventional and not officially documented, can disable guaranteed copy elision. This approach may help resolve specific problems related to copy initialization in C++.

### Application and Implications:
- Optimizing Compilation: Adjusting compilation settings and syntax choices can significantly impact how code initializes variables and handles operations.

- Maintaining Compatibility: Switching to C++14 mode or using specialized compile options to address specific issues can enhance compatibility with different compiler versions and ensure the smooth operation of your code.

- Troubleshooting and Diagnosis: Your findings provide valuable insights for developers encountering similar issues in their development environment, offering a potential workaround to investigate and implement.

By sharing your workaround, you're contributing valuable information to the programming community and helping others navigate similar challenges in their projects. Thank you for sharing these detailed insights and solutions to address issues with Studio in C++ environments.
 


Back
Top