VTK Variant

I am working with vtkSQLiteDatabase, vtkTable, and vtkVariant. The vtkVariant class provides various methods to convert the data it holds into different formats such as int, float, char, and string. However, when I use the toString method, I am unable to cast the data to std::string type.

I also tried the simplest example of vtkVariant from the VTK examples (included below), but it doesn’t seem to work. Has anyone else encountered similar issues with vtkVariant or have any suggestions or solutions? I am using VTK 9.4 and the ISO C++20 Standard on Windows.

VTK variant example:

#include <vtkVariant.h>

#include
#include

int main(int, char*)
{
double dVal = vtkVariant(“2”).ToDouble();
std::cout << "dVal: " << dVal << std::endl;
// I get the error in following line of code
std::string strVal = vtkVariant(dVal).ToString();
std::cout << "strVal: " << strVal << std::endl;
return EXIT_SUCCESS;
}

Here an example like this compiles

cmake_minimum_required(VERSION 3.13)
project(Variant
LANGUAGES CXX)

# -----------------------------------------------------------------------------
# Handle VTK dependency
# -----------------------------------------------------------------------------

# Enable C++20 for the project
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)  # Ensure the standard is required.
set(CMAKE_CXX_EXTENSIONS OFF)        # Use only standard-compliant C++.

find_package(VTK
  COMPONENTS
    CommonCore)

if (NOT VTK_FOUND)
  message("Skipping issue: ${VTK_NOT_FOUND_MESSAGE}")
  return ()
endif ()

# -----------------------------------------------------------------------------
# Compile example code
# -----------------------------------------------------------------------------

add_executable(Variant Variant.cxx)

target_link_libraries(Variant
  PRIVATE
    VTK::CommonCore
)

Perhaps, you have an issue linking to debug from a release build or vice versa.