我正在做这样的事情
Class.hpp:
class Class {
private:
static const unsigned int arraySize;
int ar[arraySize+2];
};
Run Code Online (Sandbox Code Playgroud)
Class.cpp:
#include <Class.hpp>
const unsigned int arraySize = 384;
Run Code Online (Sandbox Code Playgroud)
编译器(q ++,基于g ++的QNX OS的c ++编译器)error: array bound is not an integer constant在编译单元时给了我Class.hpp(包括编译Class.cpp时).
为什么不工作?我知道静态const成员可以用作数组绑定,由C++标准保证(请参阅此anwser).但是为什么编译器看不到static const + const作为常量的结果呢?
例:
$ objdump Logger.cpp.o -t
00000000 g F .text 00000000 .hidden __sti___10_Logger_cpp_0b2ae32b
Run Code Online (Sandbox Code Playgroud) 我有一个带文字的按钮和左边的抽屉.有没有什么方法可以在保持纵横比的同时将可绘制比例调整到合适的尺寸(填充按钮的高度)?
我的布局相关摘录:
<Button
android:text="@string/add_fav"
android:id="@+id/event_fav_button"
android:layout_width="match_parent"
android:layout_height="40dp"
android:drawableLeft="@drawable/star_yellow"/>
Run Code Online (Sandbox Code Playgroud) 能比我更深入了解C++标准的人能详细说明吗?
这是我的示例程序
#include <string>
#include <iostream>
int main(int argc, char* argv[]) {
const std::string message("hello world");
std::cout << std::hex << (void*)message.c_str() << std::endl;
const std::string& toPrint = (argc > 0) ? message : "";
std::cout << std::hex << (void*)toPrint.c_str() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在一台机器上它这样做:
# g++ --version && g++ str_test.cpp && ./a.out
g++ (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even …Run Code Online (Sandbox Code Playgroud)