在我的android项目中,我尝试使用android.support.v4.widget.DrawerLayout.
在它之前我把它添加到libs库中(cp MySdkForder/extras/android/support/v4/android-support-v4.jar MyProjectFolder/libs)
之后我把它添加到classpath这样:
所以我有这样的代码在我的main.xml文件
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
这个我带到了某个地方 developer.android.com
Idea使这段代码完全正常
当我尝试启动它时问题就开始了.当我按下时,run我有以下错误adb
Cannot reload AVD list: cvc-enumeration-valid: Value '280dpi' is not facet-valid with respect to enumeration '[ldpi, mdpi, tvdpi, hdpi, xhdpi, 400dpi, xxhdpi, 560dpi, xxxhdpi]'. It must be a value from the enumeration.
Error parsing /usr/lib/android/android-sdk-linux/system-images/android-22/android-wear/armeabi-v7a/devices.xml
cvc-enumeration-valid: Value …Run Code Online (Sandbox Code Playgroud) 我试图创建自己的结构.所以我写了这段代码.
struct node
{
int val, id;
node(int init_val, int init_id)
{
val = init_val;
id = init_id;
}
};
node t[100];
int main()
{
...
}
Run Code Online (Sandbox Code Playgroud)
我试着编译我的程序.但是我收到了一个错误:
error: no matching function for call to 'node::node()'
note: candidates are:
note: node::node(int, int)
note: candidate expects 2 arguments, 0 provided
note: node::node(const node&)
note: candidate expects 1 argument, 0 provided
Run Code Online (Sandbox Code Playgroud) 假设我需要一些DerivedBuilder扩展一些BaseBuilder.基础构建器有一些方法foo(返回BaseBuilder).派生构建器有方法bar.方法bar应方法之后被调用foo.为了做到这一点,我可以像这样覆盖foo方法DerivedBuilder:
@Override
public DerivedBuilder foo() {
super.foo();
return this;
}
Run Code Online (Sandbox Code Playgroud)
问题是BaseBuilder有很多方法foo,我必须覆盖它们中的每一个.我不想这样做,所以我尝试使用泛型:
public class BaseBuilder<T extends BaseBuilder> {
...
public T foo() {
...
return (T)this;
}
}
public class DerivedBuilder<T extends DerivedBuilder> extends BaseBuilder<T> {
public T bar() {
...
return (T)this;
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是我还是不能写
new DerivedBuilder<DerivedBuilder>()
.foo()
.bar()
Run Code Online (Sandbox Code Playgroud)
即使T这是DerivedBuilder.为了不覆盖很多功能,我该怎么办?
想象一下,你有Windows 7,文件"passwords.txt",其中包含2000个Wifi"MyHomeWifi"密码,但其中只有一个是正确的.你有python.当然,问题是如何连接到这个wifi.我只知道,要连接到wifi,您可以在命令行中使用:
netsh wlan connect _Wifi_name_
我需要n从列表中获取最后一个元素,使用O(n)内存,所以我编写了这段代码
take' :: Int -> [Int] -> [Int]
take' n xs = (helper $! (length $! xs) - n + 1) xs
where helper skip [] = []
helper skip (x : xs) = if skip == 0 then xs else (helper $! skip - 1) xs
main = print (take' 10 [1 .. 100000])
Run Code Online (Sandbox Code Playgroud)
此代码占用O(|L|)内存,其中|L|- 是给定列表的长度.
但是当我写这段代码时
take' :: Int -> [Int] -> [Int]
take' n xs = helper (100000 - …Run Code Online (Sandbox Code Playgroud) 我正在查看Linux内核源代码(kernel.h),我发现了这个min函数的宏:
#ifndef max
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#endif
Run Code Online (Sandbox Code Playgroud)
现在我想知道(void) (&_max1 == &_max2);line 有什么作用?
我认为每个 C++ 程序员都曾在某个时候听说过“虚拟函数很慢”这句话。因此,我决定将虚拟函数与常规成员函数进行基准测试。
不幸的是,我在对“低级”C++ 代码进行基准测试方面没有太多经验,并且不知道如何正确避免编译器或硬件(主要是分支预测器)优化效果。
我现在面临的问题是,当我运行基准测试(我在下面提供)时,我几乎总是得到调用虚拟函数和常规函数具有相同速度的结果,有时虚拟函数工作得更快!
这就是我使用google/benchmark库编写基准的方式:
static void BM_MemberCall(benchmark::State& state) {
Base* b = new Derived();
for ([[maybe_unused]] auto _ : state) {
benchmark::DoNotOptimize(b->Foo());
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_MemberCall);
static void BM_VirtualCall(benchmark::State& state) {
Base* b = new Derived();
for ([[maybe_unused]] auto _ : state) {
benchmark::DoNotOptimize(b->VirtualFoo());
benchmark::ClobberMemory();
}
}
BENCHMARK(BM_VirtualCall);
Run Code Online (Sandbox Code Playgroud)
我的类定义如下,声明于util.h:
#pragma once
// generate 10 virtual functions
#define VFOO(NAME, ID, ...) \
__attribute__((noinline)) virtual int NAME ## ID ## _0() __VA_ARGS__; \
__attribute__((noinline)) virtual …Run Code Online (Sandbox Code Playgroud) 我需要更改正在登录的用户的问候语.所以我修改了文件/etc/profile.在这个问候语中我需要知道,该用户使用哪个shell并告诉用户.问题是然后我改变我的shell zsh或csh它不起作用.即使我只输入此文件,echo $SHELL它也什么也不做.我认为,当我使用时csh,zsh这个文件(/etc/profile)根本不运行.我该如何解决这个问题?
谢谢你,对不起我的英文)
我写了这样的代码
import System.Environment
import Control.Exception
import Data.List
f :: String -> [String] -> IO ()
f str [] =
putStrLn "String 2"
f str (x : xs) =
putStrLn "String 1"
main :: IO ()
main = do
xs <- getArgs
let str = head xs
let xs = tail xs
f str xs
return ()
Run Code Online (Sandbox Code Playgroud)
但是当我编译并尝试运行时,我总是只能回答 <<loop>>
ghc run.hs
./run some_string some_over_arguments
run: <<loop>>
Run Code Online (Sandbox Code Playgroud)
这段代码出了什么问题?我试着用hoogle <<loop>>但没有发现任何东西.如果我传递给f不,str xs但str [some_hardcoded_list]这段代码工作正常,所以我猜这有点不对劲xs.
在我的项目中,我需要修改一些大文本,所以在我的css文件中我写道:
#wrong_answer
{
color: red;
font-size: 30;
font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)
在我的js文件中:
function wrong_answer()
{
$("body").append("<p id='wrong_answer'>Is not correct</p>");
};
Run Code Online (Sandbox Code Playgroud)
最后我得到了红色文字,但非常非常小,如果我改变字体大小,文字的大小不会改变.
所以问题是为什么我不能改变字体大小?
我之前对这个问题有不同的答案,所以决定再问这里.
假设我有一个功能node* foo(),如果有一些失败,我做return NULL.这段代码真的返回NULL指针吗?或者这NULL是一个local temporary object?编译时我没有警告.我还可以写下这样的东西:
node* ptr = foo();
if (ptr)
printf("Not NULL");
else
printf("NULL");
Run Code Online (Sandbox Code Playgroud)
它似乎有效.(但如果这个功能是,例如const string& foo()它没有)
我需要在C++上编写自己的哈希映射.它有一个方法.get("some_string")如果这个字符串不在我的hash_map中我返回NULL.但是,如果此函数返回NULL或字符串,我无法检查我的程序.这是我的代码:
if (m.get("some_string"))
cout << m.get("some_string");
Run Code Online (Sandbox Code Playgroud)
和方法:
const string& Map::get(const string& s) {
string_node* pos = find_pos(s);
if (pos)
return pos->val;
else
return NULL;
}
Run Code Online (Sandbox Code Playgroud)
pos-> val只是一个字符串.所以我有一个错误,我无法从const字符串转换为bool.问题是我需要做什么,以防止cout我的函数返回错误NULL.我怎么检查呢?