• <noscript id="yywya"><kbd id="yywya"></kbd></noscript>
  • 發布時間:2020-09-28 23:10 原文鏈接: C++之類型轉換函數(七)

    輸出結果:

    root@txp-virtual-machine:/home/txp# g++ test.cpp
    test.cpp: In function ‘int main()’:
    test.cpp:42:15: error: conversion from ‘Test’ to ‘Value’ is ambiguous
        Value v = t;
                  ^
    test.cpp:41:10: note: candidates are:
        Test t(100);
             ^
    test.cpp:31:5: note: Test::operator Value()
        operator Value()
        ^
    test.cpp:14:6: note: Value::Value(Test&)
         Value(Test& t)

    3、小結:

    無法抑制隱式的類型轉換函數調用

    類型轉換函數可能與轉換構造函數起沖突

    當然工程中可能比較習慣用 Type toType()的公有成員代替類型轉換函數(就是換了種寫法)


  • <noscript id="yywya"><kbd id="yywya"></kbd></noscript>
  • 东京热 下载