Überladen auf const und volatile - warum funktioniert es nach Referenz?

Ich habe den Code:

#include "stdafx.h"
#include <iostream>

using namespace std;


void func(const int& a)
{
    std::cout << "func(const)" << std::endl;
}

void func(volatile int& a)
{
    std::cout << "func(volatile)" << std::endl;
}

void func(const volatile int& a)
{
    std::cout << "func(const volatile)" << std::endl;
}

int main()
{
    const int a = 0;
    const volatile int b = 0;
    volatile int c = 0;
    func(a);
    func(b);
    func(c);
    system("pause");
    return 0;
}

Der obige Code zeigt eine Überladung basierend darauf, ob die Parameter konstant / flüchtig sind. Wenn ich jedoch die Parameter ab ändereint& zuint, der Code wird nicht mehr kompiliert und ich kann nicht basierend auf const / volatile-Parametertypen überladen. Ich verstehe nicht, warum wir basierend auf const und volatile überladen können, wenn das int als Referenz übergeben wird, aber nicht, wenn es als Wert übergeben wird?

BEARBEITEN Ich sollte betonen, dass ich verstehe, was eine Referenz tut. Ich verstehe nicht, warum ein Referenzalias auf const überladen darf, ein normales int jedoch nicht.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage