我有以下代码。有一个函数需要两个int32。然后,我将指针指向它,并将其强制转换为需要三个int8的函数并进行调用。我预计会出现运行时错误,但程序运行正常。为什么这样可能?
main.cpp:
#include <iostream>
using namespace std;
void f(int32_t a, int32_t b) {
cout << a << " " << b << endl;
}
int main() {
cout << typeid(&f).name() << endl;
auto g = reinterpret_cast<void(*)(int8_t, int8_t, int8_t)>(&f);
cout << typeid(g).name() << endl;
g(10, 20, 30);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
PFviiE
PFvaaaE
10 20
Run Code Online (Sandbox Code Playgroud)
如我所见,第一个函数的签名需要两个整数,第二个函数需要三个字符。Char小于int,我想知道为什么a和b仍然等于10和20。
我尝试使用此代码设置 TabBar 选项卡背景颜色,但仅更改了选定的选项卡颜色。如何为其他标签设置颜色?另外,如何设置选项卡的文本颜色?
TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
background: Rectangle {
color: "#f4d37c"
}
TabButton {
id: cardsTabButton
height: Style.line2Height
text: qsTr("Cards")
}
TabButton {
id: errorsTabButton
height: Style.line2Height
text: qsTr("Errors")
}
}
Run Code Online (Sandbox Code Playgroud)
(左侧选项卡被选中)