MPETest fails to build on MSVS 2017


#1
1>------ Build started: Project: MPETest_App, Configuration: Release Win32 ------
1>Main.cpp
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(49): error C2440: 'initializing': cannot convert from 'const juce::MPEZone *' to 'juce::MPEZone *'
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(49): note: Conversion loses qualifiers
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): error C2672: 'std::distance': no matching overloaded function found
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): error C2782: 'iterator_traits<_Iter>::difference_type std::distance(_InIt,_InIt)': template parameter '_InIt' is ambiguous
1>C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility(1193): note: see declaration of 'std::distance'
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): note: could be 'juce::MPEZone *'
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): note: or       'const juce::MPEZone *'
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): error C2784: 'iterator_traits<_Iter>::difference_type std::distance(_InIt,_InIt)': could not deduce template argument for '_InIt' from 'juce::MPEZone *'
1>C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility(1193): note: see declaration of 'std::distance'
1>Done building project "MPETest_App.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

#2

Could you try changing line 49 in ZoneColourPicker.h to this instead?

auto* zone = zoneLayout.getZoneByChannel (midiChannel);


#3

Not sure who wrote that bit of code, but it’s a good example of why we encourage people to get in to the habit of always writing if (auto*...

e.g.

    MPEZone* zone = zoneLayout.getZoneByChannel (midiChannel);

    if (zone == nullptr)
        return Colours::transparentBlack;

    return getColourForZoneIndex (std::distance (zoneLayout.getZoneByIndex (0), zone));

would be better written

    if (auto* zone = zoneLayout.getZoneByChannel (midiChannel))
        return getColourForZoneIndex (std::distance (zoneLayout.getZoneByIndex (0), zone));

    return Colours::transparentBlack;

#4

This code has been updated since but I will update it to this cleaner version.


#5

I pulled the latest (but didn’t see any changes?!) - so tried what you asked and got this

1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(49): error C2440: 'initializing': cannot convert from 'const juce::MPEZone *' to 'juce::MPEZone *' (compiling source file ..\..\Source\Main.cpp)
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(49): note: Conversion loses qualifiers (compiling source file ..\..\Source\Main.cpp)
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): error C2672: 'std::distance': no matching overloaded function found (compiling source file ..\..\Source\Main.cpp)
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): error C2782: 'iterator_traits<_Iter>::difference_type std::distance(_InIt,_InIt)': template parameter '_InIt' is ambiguous (compiling source file ..\..\Source\Main.cpp)
1>C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility(1193): note: see declaration of 'std::distance' (compiling source file ..\..\Source\Main.cpp)
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): note: could be 'juce::MPEZone *' (compiling source file ..\..\Source\Main.cpp)
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): note: or       'const juce::MPEZone *' (compiling source file ..\..\Source\Main.cpp)
1>d:\devel\JUCE\examples\mpetest\source\ZoneColourPicker.h(54): error C2784: 'iterator_traits<_Iter>::difference_type std::distance(_InIt,_InIt)': could not deduce template argument for '_InIt' from 'juce::MPEZone *' (compiling source file ..\..\Source\Main.cpp)
1>C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility(1193): note: see declaration of 'std::distance' (compiling source file ..\..\Source\Main.cpp)

#6

@Dub the error you pasted is what I get without changing the code.

When I change line 49:

MPEZone* zone = zoneLayout.getZoneByChannel (midiChannel);

to

auto* zone = zoneLayout.getZoneByChannel (midiChannel);

then everything is fine.


#7

@McMartin
/ @noahdayan
Yes, sorry, scratch that, not sure what happened to my copy - Re pulled all, and tried again pasting just
auto* zone = zoneLayout.getZoneByChannel (midiChannel);
and you’re right, it built. Thanks


#8

@jules @noahdayan does one of you intend to fix this compilation error or should I make a Pull Request?


#9

We’ll sort it out - I assumed Noah had already changed it, but I’ll check!


#10

It’s been fixed but will be updated with other example improvements all at once.