小编Non*_*hal的帖子

无符号字符c = 255是"11111111"还是不是?

这是我的问题代码:

#include "stdio.h"

int main()
{
        char a = -1;
        unsigned char b = 255;
        unsigned char c = 0;
        if((~a) ==  c)
                printf("OK 1");
        else
                printf("bad 1");
        printf("\n");
        if((~b) ==  c)
                printf("OK 2");
        else
                printf("bad 2");
        printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

我希望这打印:

OK 1

OK 2
Run Code Online (Sandbox Code Playgroud)

但是,我得到了1和坏2!

如果unsigned char b是255(11111111),那么~b应该是00000000.为什么它不等于c?

我使用gcc在Linux SUSE上工作.

c binary char

9
推荐指数
1
解决办法
3874
查看次数

为什么我们应该使用temprary对象来引发事件?

大多数情况下,当我们使用MVVM时,我们使用INotifyPropertyChanged接口向绑定提供通知,一般实现如下所示:

public class MyClass : INotifyPropertyChanged
{
    // properties implementation with RaisePropertyChanged

    public event PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

每当我从专家那里读到代码时,这对我来说都很好 - 他们写了类似的代码:

public class MyClass : INotifyPropertyChanged
{
    // properties implementation with RaisePropertyChanged

    public event PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName)
    {
        var tempchanged = PropertyChanged;
        if (tempchanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想知道为PropertyChanged事件创建临时对象的确切原因是什么.

这只是一种好的做法,还是有任何与之相关的其他好处?

我找到了Jon的回答和解释的例子:

了解C#:使用临时变量引发事件

以下是了解此问题的示例代码:

using System;
using System.Collections.Generic;
using …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf

7
推荐指数
1
解决办法
360
查看次数

占用剩余水平空间并在小屏幕上垂直堆叠的Div

我需要div水平并排堆叠两个元素,其中右边的元素应该自动调整其大小到其内容(最大给定宽度),左边的元素应该只使用左边的空间.

像这样的东西: 在此输入图像描述

到目前为止没问题.我设法通过向右浮动div并将左边的溢出设置为隐藏来实现此目的:

HTML:

<div class="frame">
    <div class="right">
        I adjust my with to my content but still need to know my boundaries if I'm floated right (max-width)
    </div>

    <div class="left">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, …
Run Code Online (Sandbox Code Playgroud)

html css html5 css3 css-float

5
推荐指数
1
解决办法
2167
查看次数

参数从类型到类型&没有已知的转换

我有一个operator=在类'ssm' 中重载的函数

ssm& operator=(ssm& rhs);
Run Code Online (Sandbox Code Playgroud)

后来我使用ssm对象(它的SSM)作为另一个类(mt3dset)的成员.我使用以下声明来初始化构造函数中的该成员.

itsSSM= ssm();
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:

错误:'((mt3dSet*)this中的'operator ='不匹配 - > mt3dSet :: itsSSM = ssm()'

错误:参数1从'ssm'到'ssm&'没有已知的转换

这是编译器的问题(g ++ 4.7)?(如有需要,请询问更多信息)

c++ operator-overloading

5
推荐指数
2
解决办法
6899
查看次数

notifyAll()抛出IllegalMonitorStateException

我正在设计两个线程:一个必须获取播放器的名称,第二个线程必须等待设置的名称才能继续,但第一个线程中的notify()all抛出了IllegalMonitorStateException错误.

private NameFecth nameFetch;
private UseName useName;
private Object nameSetLock; 
public static void method{
   nameSetLock = new Object()
   nameFetch = new NameFetch(nameSetLock);
   useName = new UseName(nameSetLock);
   Thread nameFetchThread = new Thread(nameFetch);
   nameFetchThread.start();
   Thread useNameThread = new Thread(useName);
   useNameThread.start();
}

public class NameFetch implements Runnable{
    /*variables and constructers*/

    public void run(){
       /*get name and set the variable somehow*/
       synchronized(nameSetLock){
         notifyAll();
       }
    }
}

public class UseName implements Runnable{
    /*variables and constructers*/

   public void run(){
     while(!nameBeenSet){
       synchronized(nameSetLock){
         try{
           wait();
         }catch(InterruptedException e) {} …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading

5
推荐指数
1
解决办法
6219
查看次数

Microsoft企业库缓存应用程序块不是线程安全的?

我创建了一个超级简单的控制台应用程序来测试企业库缓存应用程序块,行为令人困惑.我希望我搞砸了一些容易在设置中修复的东西.为了测试目的,我让每个项目在5秒后过期.

基本设置 - "每秒选择0到2之间的数字.如果缓存还没有它,请将其放在那里 - 否则只需从缓存中获取它.在LOCK语句中执行此操作以确保线程安全.

App.config中:

<configuration>
  <configSections>
    <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <cachingConfiguration defaultCacheManager="Cache Manager">
    <cacheManagers>
      <add expirationPollFrequencyInSeconds="1" maximumElementsInCacheBeforeScavenging="1000"
      numberToRemoveWhenScavenging="10" backingStoreName="Null Storage"
      type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      name="Cache Manager" />
    </cacheManagers>
    <backingStores>
      <add encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      name="Null Storage" />
    </backingStores>
  </cachingConfiguration>
</configuration>
Run Code Online (Sandbox Code Playgroud)

C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

namespace ConsoleApplication1
{
    class Program
    {
        public static ICacheManager cache = CacheFactory.GetCacheManager("Cache Manager");
    static …
Run Code Online (Sandbox Code Playgroud)

.net c# caching enterprise-library thread-safety

4
推荐指数
2
解决办法
2万
查看次数

Spring:url无法正确解析链接

虽然我对Java很有经验,但我对Spring框架和Web应用程序都很陌生.当我在本地tomcat服务器上运行我的站点时,URL为:http://localhost:8080/myApp/

现在请求映射将我委托给我的主页:

@RequestMapping(value = "/", method = RequestMethod.GET)
public String someMethod(Model model) { ... 
   return "index"; }
Run Code Online (Sandbox Code Playgroud)

现在在一个文件中index.xhtml我链接到另一个页面,<a href="apps/">link</a> 但当我想链接回我必须使用的索引页面<a href="../index/">link</a>.我搜索了一个解决方案,发现:

<spring:url value='/apps' var="apps_url" />
<a href="${apps_url}">link</a>
Run Code Online (Sandbox Code Playgroud)

但是春天:网址总是解析为http://localhost:8080/myApp/- 我目前所在的网页.另外,当我只使用这样的链接:时<a href="/otherSite">link</a>,它总是解析为,http://localhost:8080/otherSite而不是http://localhost:8080/myApp/otherSite像我预期的那样.如何让我的链接工作?是http://localhost:8080/myApp隐式定义为我的上下文还是可以/应该更改为http://localhost:8080/?

此外,本地tomcat服务器上的URL与Web应用程序发布时的URL之间是否存在任何连接?

以下是我的一些应用程序文件:

servlet的context.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc java-ee

3
推荐指数
1
解决办法
2万
查看次数

如何用css选择特定标签的第n个孩子?

是否可以选择第4个<p>标签并在下面的代码中用CSS隐藏它?(它既没有类属性也没有id)

<form id="registerform" name="registerform" action="http://localhost/wordpress/wp-login.php?action=register" method="post">
   <p></p>
   <p></p>
   <style></style>
   <p></p>
   <p> //this tag
    <label>
      gen_code
      <br>
      <input id="gen_code" class="input" type="text" name="gen_code" value="" size="25" tabindex="20" style="font-size: 20px; width: 97%; padding: 3px; margin-right: 6px;">
    </label>
   </p>  
   <p class="submit"></p>
</form>
Run Code Online (Sandbox Code Playgroud)

css css-selectors

1
推荐指数
1
解决办法
3101
查看次数

无法向JList添加复选框

我是编程的新手,我无法添加JCheckbox到JList.没有错误但没有显示任何内容.

JFrame f=new JFrame();
String[] labels={"a","b","c","d","e"};
JCheckBox[] ch=new JCheckBox[labels.length];

JList list=new JList();

for (int i = 0; i < labels.length; i++) {
    ch[i]=new JCheckBox("CheckBox"+i);
    list.add(ch[i]);
}

JScrollPane pane=new JScrollPane(list);
f.add(pane);
f.setVisible(true);
Run Code Online (Sandbox Code Playgroud)

java swing jlist jcheckbox

1
推荐指数
1
解决办法
7199
查看次数

hql没有删除查询确定

sessionFactory.getCurrentSession().createQuery(
    "delete from Attendance attend where attend.id in(Select att.id from Attendance att where att.dat= :dat and att.cls_id= :cls_id)"
    ).setDate("dat", dat).setShort("cls_id",cls_id); // delete all records with matching date and cls_id
sessionFactory.getCurrentSession().flush();
sessionFactory.getCurrentSession().clear();
// immediate save after delete in same transaction
for(Attendance a : absent){
    sessionFactory.getCurrentSession().save(a);
}
Run Code Online (Sandbox Code Playgroud)

我试图删除具有特定条件的现有行,因为我保存的对象可能已存在于表中.但是删除不起作用,并且插入了重复值.请让我知道代码的哪一部分是错误的.

java hibernate hql spring-mvc

0
推荐指数
1
解决办法
178
查看次数

了解复制构造函数

我已经读过,如果我们在类中有指针,那么我们需要实现自己的复制构造函数; 否则,两个类将指向同一个内存位置的指针,并且在其中一个类上调用delete会使另一个类也为空.我试图通过编写如下代码来模拟上述条件:

class A
{
    private:
        int *p;
    public:
        A()
        {
            p = new int(10);
        }

        ~A()
        {
            delete p;
            cout << "Calling destructor" << endl;
        }
};

int main(int argc, char **argv)
{
    A a;
    A aa = a;
}
Run Code Online (Sandbox Code Playgroud)

我期待抛出一些异常,因为我没有明确声明我的拷贝构造函数,我也在使用指针.但程序运行完美.任何人都可以建议修改,以便我能够理解在什么条件下会发生异常?

c++ copy-constructor

0
推荐指数
1
解决办法
204
查看次数

如何使用$(this)获取父级

我正在努力进一步理解遍历和正确使用$(this).

我理解$(this)用于参考上下文.但是,假设我有三个彼此相同的项目(按HTML方式),如果用户点击输入,我希望事件不仅发生在用户选择的项目上,而且能够访问父元素".item"同样.这样,我可以隐藏其他元素,".item"因为上下文将是"input"用户单击的内容.

这是我感到困惑的地方.当用户点击input($('input').on('click', doSomething);)时,我仅限于输入的上下文 - 输入中没有任何内容,所以我想访问输入上下文之外的其他元素.

然后我试着$(this)说我只希望这个事件只发生在这个项目上,不会影响所有项目.

这是一个代码示例:JSFIDDLE

我已经尝试过对此进行研究,但是我找不到这样的实例的大量信息,所以希望这也可以使其他人受益.随意对内容/标题进行编辑,因为我试图尽可能具体.

javascript jquery

0
推荐指数
1
解决办法
58
查看次数