我刚刚将一个项目转换为VS 2010,而且名称空间正在发生一些奇怪的事情.让我举一个例子,下面的代码用于在VS2008中工作:
namespace MySystem.Core.Object
{
using MySystem.Core.OtherObject;
...
}
Run Code Online (Sandbox Code Playgroud)
但是现在它没有,它要么将整个事物放在命名空间之外,如下所示:
using MySystem.Core.OtherObject;
namespace MySystem.Core.Object
{
...
}
Run Code Online (Sandbox Code Playgroud)
或者像以下一样重写:
namespace MySystem.Core.Object
{
using OtherObject;
...
}
Run Code Online (Sandbox Code Playgroud)
我理解为什么这样做可能是处理这个问题的正确方法,但现在我们必须改变数千行代码!哪个不酷.
有没有想过规避这个要求?
我把这个问题写成代码中的注释,我觉得这样比较容易理解.
public class Xpto{
protected AbstractClass x;
public void foo(){
// AbstractClass y = new ????? Car or Person ?????
/* here I need a new object of this.x's type (which could be Car or Person)
I know that with x.getClass() I get the x's Class (which will be Car or
Person), however Im wondering how can I get and USE it's contructor */
// ... more operations (which depend on y's type)
}
}
public abstract class AbstractClass { …Run Code Online (Sandbox Code Playgroud) 当我对一个加载.so的程序运行GDB时,该程序链接到pthreads,GDB报告错误"无法找到新的线程:泛型错误".
请注意,我运行的可执行文件未与pthreads链接.
有线索吗?
$ gdb --args lua -lluarocks.require GNU gdb (GDB) 7.0-ubuntu Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/bin/lua...(no debugging symbols found)...done. (gdb) run Starting …
以下代码无法编译:
#include <iostream>
class Foo {
std::string s;
public:
const std::string& GetString() const { return s; }
std::string* GetString() { return &s; }
};
int main(int argc, char** argv){
Foo foo;
const std::string& s = foo.GetString(); // error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
const1.cc:11: error:
invalid initialization of reference of type 'const std::string&'
from expression of type 'std::string*
Run Code Online (Sandbox Code Playgroud)
它确实有一定意义,因为foo它不是类型const Foo,只是Foo,因此编译器想要使用非const函数.但是,为什么不能通过GetString查看我赋给它的(类型)变量来识别我想调用const 函数?我发现这种情况令人惊讶.
function(char* name)
{
char sql[50];
sprintf(sql, "select %s;", name);
}
Run Code Online (Sandbox Code Playgroud)
什么是确保只有50个字符的名称被复制到sql的最佳方法,在这个案例名称大于sql可以容纳的名称?(带有N参数的sprintf?)
谢谢.
在我的代码中,我使用的是JSF - 前端,EJB-Middile Tier和JPA连接到DB.使用Webservices.使用MySQL作为DAtabase来调用EJB.我创建了Voter表,我需要在其中插入记录.我将值从JSF传递给EJB,它正在工作.我创建了JPA控制器类(它自动生成基于数据库类的持久性代码)例如:获取实体管理器等,
em = getEntityManager();
em.getTransaction().begin();
em.persist(voter);
em.getTransaction().commit();
Run Code Online (Sandbox Code Playgroud)
我也创建了命名查询:
@NamedQuery(name = "Voter.insertRecord", query = "INSERT INTO Voter v
values v.voterID = :voterID,v.password = :password,v.partSSN = :partSSN,
v.address = :address, v.zipCode = :zipCode,v.ssn = :ssn,
v.vFirstName = :vFirstName,v.vLastName = :vLastName,v.dob = :dob"),
Run Code Online (Sandbox Code Playgroud)
但仍然无法插入记录?
任何人都可以帮我通过JPA将记录插入数据库.(持久性对象)?
如果我们使用容器管理实体管理器,我们是否需要再次编写开始和提交事务...像这样:
em.getTransaction().begin();
em.getTransaction().commit();
Run Code Online (Sandbox Code Playgroud)
我已经写了:
Voter v= new Voter(voterID,password,partSSN,address,zipCode,ssn,vFirstName,vLastName,d1,voterFlag);
em.persist(v);
Run Code Online (Sandbox Code Playgroud)
但它导致Null指针异常.
SEVERE: java.lang.NullPointerException
at ejb.Registration.reg(Registration.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4038)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5223)
Run Code Online (Sandbox Code Playgroud) 我正在设计一个数据库,我想规范化数据库.在一个查询中,我将加入大约30-40个表.如果它变得非常受欢迎,这会损害网站性能吗?这将是主要查询,它将在50%的时间内被调用.我将加入关于两个表的其他查询.
我现在可以选择标准化或不标准化,但如果标准化将来成为问题,我可能需要重写40%的软件,这可能需要很长时间.在这种情况下,规范化真的会受到伤害吗 在我有空的时候,我应该现在正常化吗?
c# performance normalization denormalization sql-server-2008
在Haskell和OCaml中,都可以从C程序调用语言.为广泛使用这种技术的Windows,Mac或Linux创建Native应用程序有多可行?
(我知道有像wxHaskell这样的GUI库,但是假设有人希望只用外语获得一部分应用程序逻辑.)
或者这是一个可怕的想法?
我有一个Android活动,它从URL获取RSS提要,并使用SAX解析器将XML中的每个项目粘贴到一个数组中.这一切都很好,但正如预期的那样,需要花费一些时间,所以我想在后台使用AsyncActivity来完成它.我的代码如下:
class AddTask extends AsyncTask<Void, Item, Void> {
protected void onPreExecute() {
pDialog = ProgressDialog.show(MyActivity.this,"Please wait...", "Retrieving data ...", true);
}
protected Void doInBackground(Void... unused) {
items = parser.getItems();
for (Item it : items) {
publishProgress(it);
}
return(null);
}
protected void onProgressUpdate(Item... item) {
adapter.add(item[0]);
}
protected void onPostExecute(Void unused) {
pDialog.dismiss();
}
}
Run Code Online (Sandbox Code Playgroud)
我称之为在onCreate()与
new AddTask().execute();
Run Code Online (Sandbox Code Playgroud)
这行items = parser.getItems()很好 - items是包含XML中每个项目的arraylist.我现在面临的问题是,在启动活动,这是我创造的ProgressDialog onPreExecute()不显示,直到之后的doInBackground()方法完成.即我得到一个黑色的屏幕,一个长时间的停顿,然后一个完整填充列表中的项目.为什么会发生这种情况?为什么不是UI绘图,ProgressDialog显示,解析器获取项目并逐步将它们添加到列表中,然后ProgressDialog解雇?
知道一个字段的问题对我有很大的帮助,特别是因为它允许我与那些比我更了解的人聪明地交谈,所以我想找到一个很好的功能编程术语词典.
例如,我反复遇到这些:Functor,Arrow,Category,Kleisli,Monad,Monoid,一个名副其实的态射动物园等等.我也注意到其中许多出现了前缀,如"covariant","co-","endo- "等
其中,我可以说我实际上理解Monoid和Covariant有点得到Monad,但其余的仍然是我的胡言乱语.(请注意,我并不是说这个列表是详尽的,我不打算在这里定义或描述这些,我正在寻找学习资源.)
有人能指出我的FP词汇吗?它不需要在线,只要有可能找到它(并且它不是一个罕见的卷,我必须支付几十美元).
c++ ×2
java ×2
android ×1
c ×1
c# ×1
const ×1
debugging ×1
function ×1
gdb ×1
haskell ×1
jpa ×1
namespaces ×1
ocaml ×1
overloading ×1
performance ×1
pthreads ×1
reflection ×1
ubuntu ×1