在C++模板函数foo()中,对:: bar(TT*)的调用在gcc 4.4.3下给出以下错误:
g++ -o hello.o -c -g hello.cpp
hello.cpp: In function 'void foo(std::vector<TT*, std::allocator<TT*> >&)':
hello.cpp:8: error: '::bar' has not been declared
Run Code Online (Sandbox Code Playgroud)
这是有问题的代码:
// hello.cpp
#include <vector>
template<typename TT> void foo(std::vector<TT*> &vec)
{
TT *tt;
::bar(tt);
vec.push_back(tt);
}
class Blah
{
};
void bar(Blah *&)
{
}
int main(int argc, char *argv[])
{
std::vector<Blah*> vec;
foo(vec);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
C++区分依赖于模板参数(此处为TT)的符号和独立且可立即求值的符号.
很明显,编译器认为我的:: bar(TT*)调用是独立的,并尝试立即解决它.正如显然,该函数调用是依赖于TT,因为函数调用采用类型TT*的参数,所以编译器应该等到把foo(VEC)实例解析::巴(TT*).
这是一个gcc错误还是我遗漏了一些关于C++模板的微妙之处?
编辑:这是一个稍微复杂的例子,有两个版本的:: bar()来澄清声明顺序不是问题的问题.在解析模板时,编译器无法知道下面的main()是否将使用TT = Blah或TT = Argh来实例化模板函数.因此,编译器不应该在最早(如果有的话)第35行第28行之前给出错误.但是第8行第16 行给出了错误. …
有没有办法从任何子控件获取主页面对象?作为一种可能的解决方案,我看到这里冒泡父母并在父母属于PhoneApplicationPage类型时立即停止.这对我来说没问题,但是如果我需要从其他页面那样做呢?即如何从应用程序中的任何位置获取应用程序的主页?
至于最佳实践,使用之间是否存在有意义的差异:
Double d;
Run Code Online (Sandbox Code Playgroud)
和
double d;
Run Code Online (Sandbox Code Playgroud)
我知道最佳实践充满了矛盾,所以我知道答案可能会有所不同.我只是想知道两者之间的实用差异.
我是Rails 3的新手,我正在尝试制作RSS/Atom提要.我知道auto_discovery_link_tag,但是相关的控制器/动作应该是什么样的?
谢谢!
我正在使用Resharper(使用StyleCop插件,虽然我不认为这与问题/答案相关)在我们的代码库中强制执行命名约定.几乎无处不在,这种方法非常出色,只有一个例外.
对于测试方法名称,我更喜欢以下约定:
ThingOrBehaviourUnderTest_Action_ExpectedOutcome
目前这导致命名警告不一致,到目前为止我只是忽略了它(我知道我可以在该文件中禁用警告,但是它会禁用所有其他命名不一致的警告).在我可以分配的样式列表中,Resharper提供了驼峰案例,这将导致:
ThingOrBehaviourUnderTestActionExpectedOutcome
或者用下划线分隔的单词:
Thing_or_behaviour_under_test_action_expected_outcome
两者都接近我想要的,但不完全在那里.我想我正在采用一种允许下划线作为驼峰测试方法名称中的有效字符的方法,或者支持自定义命名约定的方法.这可能吗?
System.out.print("Enter an integer: ");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int lArray = x - 2;
int[] newArray = new int[lArray];
System.out.println("Let's display all possible integers...");
for (int i = 0; i <= newArray.length; i++) {
newArray[i] = i + 2;
System.out.print(newArray[i] + " ");
}
Run Code Online (Sandbox Code Playgroud)
我最近刚刚开始使用Java,但我确信如果我用其他语言编写类似的代码,我会遇到同样的问题.这是一个应用程序的摘录,它列出了用户输入之前的所有素数.
将x-2用作lArray的定义的原因是因为数组的长度将是从2到数字{2,3,4,5 ...... x}的所有整数.
我注意到了这条线
for (int i = 0; i <= newArray.length; i++) {
Run Code Online (Sandbox Code Playgroud)
如果我i <= newArray改为i < newArray,代码可以正常工作.但是,如果x是素数,则省略用户的输入x,这是一个问题.
我正在使用JSF数据表.表中的一列是命令按钮.
单击此按钮时,我需要使用表达式语言传递几个参数(如所选行的值).这个参数需要传递给JSF托管bean,它可以对它们执行方法.
我使用了以下代码片段,但我在JSF bean上获得的值始终为null.
<h:column>
<f:facet name="header">
<h:outputText value="Follow"/>
</f:facet>
<h:commandButton id="FollwDoc" action="#{usermanager.followDoctor}" value="Follow" />
<h:inputHidden id="id1" value="#{doc.doctorid}" />
</h:column>
Run Code Online (Sandbox Code Playgroud)
豆方法:
public void followDoctor() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestMap = context.getExternalContext().getRequestParameterMap();
String value = (String)requestMap.get("id1");
System.out.println("Doctor Added to patient List"+ value);
}
Run Code Online (Sandbox Code Playgroud)
如何使用命令按钮将值传递给JSF托管bean?
我正在开发一个Android应用程序,在其中我从Web服务下载JSON数据.解析数据的类看起来像这样:
public class JsonCourseParser implements CourseParser {
public Course parseCourse(String courseData) {
Course result;
try {
JSONObject jsonObject = new JSONObject(courseData);
...
result = new Course("foo", "bar");
} catch (JSONException e) {
result = null;
}
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
这构建得很好,当我parseCourse()从我的应用程序内部调用时它可以正常工作,但是当我尝试在单元测试中测试此方法时,我得到了以下异常:
java.lang.NoClassDefFoundError: org/json/JSONException
at JsonCourseParserTest.initClass(JsonCourseParserTest.java:15)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: …Run Code Online (Sandbox Code Playgroud) 我正在我的第一个真正的应用程序,我在用户设置中添加.我正在使用Java并且非常OO(并试图保持这种方式)所以这是我的想法:
main()并将其全部"下线"传递给所需的对象(数组)我理解每种方法的一些基本优缺点(即时间与大小),但我正在寻找一些外部输入,以了解他们过去成功使用的实践.
我已经看到了如何使这些例子ContentProvider都使用UriMatcher#match(Uri)的方法中insert,query,update,和delete方法来轻松处理所有的URI模式的内容提供商响应(如:http://developer.android.com/ resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html).这似乎还好我直到今天,当我注意到的ContentProvider是API文档insert,query,update,和delete"可以[全部]从多个线程调用".此外,UriMatcher文档没有说明线程安全性或是否match是可重入的.
我是否需要担心同步调用match上的共享,static实例UriMatcher是我的实现内使用insert,query,update,和delete?