灯角

文章 0 评论 0 浏览 23

灯角 2024-12-20 12:21:21

我认为您误解了 & 运算符在这种情况下的作用。获取变量的地址 (&var) 与表示参数将作为引用传递(正如您所见,在 const string 中) &a)。

您的代码实际上所做的是隐式创建一个新的 string 对象,该对象使用字符串 "bye" 进行初始化,然后该对象通过引用传递Dude 构造函数。也就是说,您的代码本质上是:

Dude d2 = Dude(string("bye"));

然后构造函数通过引用接收该字符串对象,并通过复制构造函数将其分配给 x

I think you're misunderstanding what the & operator does in this context. Taking the address of a variable (&var) is different from signifying that a parameter is to be passed as a reference (as you have, in const string &a).

What your code is actually doing is implicitly creating a new string object that's initialized with the string "bye", and then that object is passed by reference to the Dude constructor. That is, your code is essentially:

Dude d2 = Dude(string("bye"));

and then the constructor receives that string object by reference and assigns it to x via a copy constructor.

C++:使用 &引用传递运算符

灯角 2024-12-20 11:41:59

如果您使用的是view.setVisibility(View.GONE)..那么请尝试View.INVISIBLE
这里视图=(你的文本视图,按钮任何东西)

if you are using view.setVisibility(View.GONE)..then try View.INVISIBLE
here view = (your textview,button anything)

相对布局简单位置

灯角 2024-12-20 10:52:41

代码中需要注意的事项:

  • T 的定义是递归的。如果需要的话可以制定一个界面。
  • 正如编译器明确指出的那样,您的分配是错误的! :-)

    Comparable tmp = a[j];

这会起作用,因为这是真实且正确的。由于 T 扩展了 Comparable,因此 T 是一个 Comparable。

  a[j - 1] = tmp;

这是行不通的,因为您试图将超类实例分配给子类实例。 Comparable 不保证具有 T 行为。因此出现了错误。

您可以尝试参数化该函数所在的类。使用该参数来定义 T。同样,您可能需要使用接口。除非我们更多地了解其他相关的设计目标,否则很难提供建议。就代码而言,该错误是正确且合理的。

Things to note down in your code:

  • Your definition of T is recursive. May be work out an interface if you need to.
  • Your assignment is wrong as clearly pointed out by the compiler! :-)

    Comparable tmp = a[j];

this will work, because this is true and correct. Since T extends Comparable, T is-a Comparable.

  a[j - 1] = tmp;

This will not work, because you are trying to assign a superclass instance to a subclass instance. Comparable is not guaranteed to have T behavior. Hence the error.

You can try and parameterize your class in which this function lies. Use that parameter to define T. Again, You may need to work with interfaces. Unless we know more about the other related design goals, difficult to advice. Code wise, the error is correct and justified.

处理 Java 泛型错误

灯角 2024-12-20 10:09:16

您还可以使用 2D 变换。下面的代码片段对其进行了说明,其中列表缩放了 25%。

注意此处使用 Bootstrap 的唯一目的是布局演示(效果前/后)。


ul#before {
}

ul#after {
  transform: scale(1.25);
}

div.container, div.row {
  padding: 20px;
}

ul {
  border: 6px solid #000000;
}
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Bootstrap theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- HTML -->
<div class="container">
  <div class="row">
    <div class="col-xs-5">
      Before
    </div>
    <div class="col-xs-5 col-xs-offset-1">
      After (scale 25%)
    </div>
  </div>

  <div class="row">
    <div class="col-xs-5">
      <ul id="before">
        <li>Lorem ipsum dolor sit amet...</li>
        <li>In vel ante vel est accumsan...</li>
        <li>In elementum libero vel...</li>
        <li>Nam ut ante a sem mattis...</li>
        <li>Curabitur fermentum nisl...</li>
        <li>Praesent vel risus ultrices...</li>
      </ul>
    </div>
    <div class="col-xs-5 col-xs-offset-1">
      <ul id="after">
        <li>Lorem ipsum dolor sit amet...</li>
        <li>In vel ante vel est accumsan...</li>
        <li>In elementum libero vel...</li>
        <li>Nam ut ante a sem mattis...</li>
        <li>Curabitur fermentum nisl...</li>
        <li>Praesent vel risus ultrices...</li>
      </ul>
    </div>
  </div>
</div>

<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!-- Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

参考:

You can also use 2D transform. It is illustrated in the snippet below with a list being scaled by 25%.

Nota: Bootstrap is used here for the sole purpose of layouting the demo (before/after effect).


ul#before {
}

ul#after {
  transform: scale(1.25);
}

div.container, div.row {
  padding: 20px;
}

ul {
  border: 6px solid #000000;
}
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Bootstrap theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- HTML -->
<div class="container">
  <div class="row">
    <div class="col-xs-5">
      Before
    </div>
    <div class="col-xs-5 col-xs-offset-1">
      After (scale 25%)
    </div>
  </div>

  <div class="row">
    <div class="col-xs-5">
      <ul id="before">
        <li>Lorem ipsum dolor sit amet...</li>
        <li>In vel ante vel est accumsan...</li>
        <li>In elementum libero vel...</li>
        <li>Nam ut ante a sem mattis...</li>
        <li>Curabitur fermentum nisl...</li>
        <li>Praesent vel risus ultrices...</li>
      </ul>
    </div>
    <div class="col-xs-5 col-xs-offset-1">
      <ul id="after">
        <li>Lorem ipsum dolor sit amet...</li>
        <li>In vel ante vel est accumsan...</li>
        <li>In elementum libero vel...</li>
        <li>Nam ut ante a sem mattis...</li>
        <li>Curabitur fermentum nisl...</li>
        <li>Praesent vel risus ultrices...</li>
      </ul>
    </div>
  </div>
</div>

<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!-- Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

Reference:

如何在CSS中控制列表样式类型光盘的大小?

灯角 2024-12-20 06:32:42

标准没有指定确切的哈希算法,因此结果
会有所不同。 VC10使用的算法似乎并没有采取所有的
如果字符串长度超过 10 个字符,则考虑字符;它
1 + s.size() / 10 的增量前进。这是合法的,
尽管从 QoI 的角度来看,相当令人失望;这样的哈希码
众所周知,对于某些典型的数据集(例如
网址)。我强烈建议您将其替换为 FNV 哈希或
一个基于梅森素数:

FNV 哈希:

struct hash
{
    size_t operator()( std::string const& s ) const
    {
        size_t result = 2166136261U ;
        std::string::const_iterator end = s.end() ;
        for ( std::string::const_iterator iter = s.begin() ;
              iter != end ;
              ++ iter ) {
            result = (16777619 * result)
                    ^ static_cast< unsigned char >( *iter ) ;
        }
        return result ;
    }
};

梅森素数哈希:

struct hash
{
    size_t operator()( std::string const& s ) const
    {
        size_t result = 2166136261U ;
        std::string::const_iterator end = s.end() ;
        for ( std::string::const_iterator iter = s.begin() ;
              iter != end ;
              ++ iter ) {
            result = 127 * result
                   + static_cast< unsigned char >( *iter ) ;
        }
        return result ;
    }
};

(FNV 哈希据说更好,但梅森素数哈希将是
在很多机器上更快,因为乘以 127 通常是
明显快于乘以 16777619。)

The exact hash algorithm isn't specified by the standard, so the results
will vary. The algorithm used by VC10 doesn't seem to take all of the
characters into account if the string is longer than 10 characters; it
advances with an increment of 1 + s.size() / 10. This is legal,
albeit from a QoI point of view, rather disappointing; such hash codes
are known to perform very poorly for some typical sets of data (like
URLs). I'd strongly suggest you replace it with either a FNV hash or
one based on a Mersenne prime:

FNV hash:

struct hash
{
    size_t operator()( std::string const& s ) const
    {
        size_t result = 2166136261U ;
        std::string::const_iterator end = s.end() ;
        for ( std::string::const_iterator iter = s.begin() ;
              iter != end ;
              ++ iter ) {
            result = (16777619 * result)
                    ^ static_cast< unsigned char >( *iter ) ;
        }
        return result ;
    }
};

Mersenne prime hash:

struct hash
{
    size_t operator()( std::string const& s ) const
    {
        size_t result = 2166136261U ;
        std::string::const_iterator end = s.end() ;
        for ( std::string::const_iterator iter = s.begin() ;
              iter != end ;
              ++ iter ) {
            result = 127 * result
                   + static_cast< unsigned char >( *iter ) ;
        }
        return result ;
    }
};

(The FNV hash is supposedly better, but the Mersenne prime hash will be
faster on a lot of machines, because multiplying by 127 is often
significantly faster than multiplying by 16777619.)

与 std::hash 发生意外冲突

灯角 2024-12-20 05:56:26

据我所知没有这样的方法。

There is no such method as far as I know.

Rails 中是否有类似于 find_or_create 的方法 find_child_or_create ?

灯角 2024-12-20 05:41:56

DropDownListFor 本身不支持它,您可以对 DropDownListFor 的结果执行查找/替换,也可以编写自己的 HTML 帮助程序来执行此操作。请参阅类似的问题:

ASP.NET MVC:将自定义属性放入选择列表中的选项标签

DropDownListFor doesn't support it natively, you can either do a find/replace on the result of DropDownListFor or you can write your own HTML helper to do it. See this similar question:

ASP.NET MVC: putting custom attributes into option tag in select list

MVC3 中的 HTML 5 下拉菜单

灯角 2024-12-20 04:40:41

这是因为复制构造函数是私有的..

您的代码正在

  • 创建一个临时 exampleClass 并调用默认构造函数 exampleClass()
  • 尝试使用私有复制构造函数将生成的临时对象分配给 e1

Its because the copy constructor is private..

your code is

  • creating a temporary exampleClass and invoking the default constructor exampleClass()
  • attempting to assign the resulting temporary object to e1 using the private copy constructor

为什么编译器会在这个问题上困扰我?

灯角 2024-12-20 04:19:19

您通常不应显式设置 GOROOT。 go 命令根据其自己的目录位置自动识别适当的 GOROOT


GOPATH 默认为 $HOME/go。如果你想把它放在其他地方,你只需要明确地设置它。

GOPATH 包含:

  • 使用 go install 安装的二进制文件,位于 $GOPATH/bin
    • 可以使用 GOBIN 环境变量覆盖此位置。
  • 下载的模块源代码和校验和的缓存,位于 $GOPATH/pkg /mod
    • 可以使用 GOMODCACHE 环境变量覆盖此位置。

如果您同时设置了GOBINGOMODCACHE,并且没有设置GO111MODULE=off,那么GOPATH本身应该本质上已经没有效果。


此外,在旧版 GOPATH 模式下(当还设置了 GO111MODULE=off 时),GOPATH 包含:

  • 用于构建包的源代码,存储在以 $GOPATH/src 为根的目录树中。
  • 使用 go install 安装的非二进制文件,位于 $GOPATH/pkg

¹ 在 Go 1.17 及更早版本上也可以使用 go get 安装二进制文件,但从 Go 1.16 开始首选 go install;请参阅https://golang.org/doc/go1.16

You generally should not set GOROOT explicitly. The go command identifies the appropriate GOROOT automatically based on its own directory location.


GOPATH defaults to $HOME/go. You only need to set it explicitly if you want to put it somewhere else.

GOPATH contains:

  • Binaries installed using go install, located at $GOPATH/bin
    • This location can be overridden using the GOBIN environment variable.
  • A cache of downloaded module source code and checksums, located at $GOPATH/pkg/mod.
    • This location can be overridden using the GOMODCACHE environment variable.

If you set both GOBIN and GOMODCACHE, and do not set GO111MODULE=off, then GOPATH itself should have essentially no effect.


In addition, in the legacy GOPATH mode (when GO111MODULE=off is also set), GOPATH contains:

  • Source code used to build packages, stored in a directory tree rooted at $GOPATH/src.
  • Non-binaries installed using go install, located at $GOPATH/pkg.
    • Installing non-binary packages is no longer particularly useful: the go command has a cache of built artifacts, which has been required since Go 1.12 even in GOPATH mode.
    • The build cache is not located within GOPATH. Its location can be set with the GOCACHE environment variable.

¹ Binaries can also be installed using go get on Go 1.17 and earlier, but go install is preferred as of Go 1.16; see https://golang.org/doc/go1.16.

GOPATH 和 GOROOT 的值应该是多少?

灯角 2024-12-20 04:14:08

首先将程序分解为逻辑步骤:

  1. 获取用户的输入
  2. 检查输入是否为 4 位数字
  3. 将数字拆分为各个数字
  4. 对每个数字执行余数计算
  5. 重新组合 4 位数字,根据需要交换数字
  6. 打印输出。

我想您至少可以做到其中的一些,所以请让我们知道您到目前为止所做的事情。

First break down the program into logical steps:

  1. Get input from the user
  2. Check that the input is a 4-digit number
  3. Split up the number into individual digits
  4. Perform the remainder calculation on each digit
  5. Reassemble the 4-digit number, swapping digits as required
  6. Print the output.

I imagine you can do at least some of that, so let us know what you've done so far.

Java 中的整数操作

灯角 2024-12-19 18:05:37

我将使用事务性队列 (MSMQ) 来存储服务调用。循环将使消息出队并调用 TransactionScope 中的服务,如果调用失败,则消息看起来仍在队列中。可以通过在消息中添加到期时间来指定总体超时。如果您确实想要一个可靠的解决方案,那么这个解决方案很好,因为我猜调用该操作至关重要。

I will use a transactional queue (MSMQ) to store the service call. A loop will dequeue messages and call the service in a TransactionScope, if the call fails the message appear to be still in the queue. An ov erall timeout can be specified by adding a time to expire in the message. This solution is good if you really want a reliable solution since I guessed that calling that operation is critical.

在 C# 中重复一个函数,直到它不再抛出异常

灯角 2024-12-19 11:38:34

使用 UIDevice 属性 batteryState

[[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging

来自 UIDevice Docs

typedef enum {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,
    UIDeviceBatteryStateCharging,
    UIDeviceBatteryStateFull,
} UIDeviceBatteryState;

至于你的第二个问题。我不相信您可以确定电池组和壁式充电器之间的任何区别,因为上述 UIDeviceBatteryState 标志是设备电池可以报告的唯一“状态”。因此,电池组和壁式充电器都会显示为 UIDeviceBatteryStateChargingUIDeviceBatteryStateFull(如果电池组已插入但电量耗尽,则显示为 UIDeviceBatteryStateUnplugged) )。

Use UIDevice property batteryState:

[[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging

From UIDevice Docs:

typedef enum {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,
    UIDeviceBatteryStateCharging,
    UIDeviceBatteryStateFull,
} UIDeviceBatteryState;

As for your 2nd question. I don't believe you can determine any difference between a battery pack and a wall charger since the above UIDeviceBatteryState flags are the only "states" a device battery can report. So both a battery pack and wall charger would appear as either UIDeviceBatteryStateCharging or UIDeviceBatteryStateFull (or UIDeviceBatteryStateUnplugged if the battery pack is plugged in but out of juice).

iPhone4如何判断电源线是否插入?

灯角 2024-12-19 10:36:01

打开Xcode Organizer >文档并搜索UIPopoverController。在左侧边栏中的底部,打开“Popovers”示例代码项目。

基本上,您会发现需要在代码中的某个位置创建一个 UIPopoverController 实例:

- (void)viewDidLoad {
    ...
    /* 'contentCtrl' is an instance of UIViewController 
     * such as an UITableViewController
     */
    ...
    popover = [[UIPopoverController alloc] initWithContentViewController:contentCtrl];
    popover.popoverContentSize = CGSizeMake(320, 480);
    ...
}

并在某个时刻显示它,例如当用户按下按钮时:

- (IBAction)showPopover:(id)sender {
    UIButton *button = (UIButton *)sender;
    [popover presentPopoverFromRect:button.frame 
                             inView:self.view 
           permittedArrowDirections:UIPopoverArrowDirectionAny 
                           animated:YES];
}

我建议研究该示例。如果您需要有关 UITableView 部分的帮助,文档中提供了数十个有关该主题的示例(以及 SO 中的数百个问题)。

Open the Xcode Organizer > Documentation and search UIPopoverController. In the left sidebar, at the bottom, open 'Popovers' sample code project.

Basically you'll see that you need to create a UIPopoverController instance somewhere in your code:

- (void)viewDidLoad {
    ...
    /* 'contentCtrl' is an instance of UIViewController 
     * such as an UITableViewController
     */
    ...
    popover = [[UIPopoverController alloc] initWithContentViewController:contentCtrl];
    popover.popoverContentSize = CGSizeMake(320, 480);
    ...
}

And show it at some point, such as when the user press a button:

- (IBAction)showPopover:(id)sender {
    UIButton *button = (UIButton *)sender;
    [popover presentPopoverFromRect:button.frame 
                             inView:self.view 
           permittedArrowDirections:UIPopoverArrowDirectionAny 
                           animated:YES];
}

I'd suggest to study the sample. If you need help with the UITableView part, there are dozens of samples on the subject in the Documentation (and hundredths of questions in SO).

向 UIPopoverController 添加内容

灯角 2024-12-19 07:22:32

使用 pngquantposterizer 来减小 PNG 图像的大小(这些工具是有损的,但可以显着节省)。

您还可以使用 PNGOUT 对其进行优化,这是最好的无损优化器之一。

我已经为这些编写了 Mac GUI

Use pngquant or posterizer to reduce size of PNG images (these tools are lossy, but give significant savings).

You can also optimize them with PNGOUT, which is one of the best lossless optimizers.

I've written Mac GUI for those.

由于图像,应用程序尺寸较大。如何压缩 .PNG 图像?

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文