我已经了解到Java文件中唯一的公共类也必须具有main方法.但是,在下面你可以看到内部类中的main方法而不是?关于源文件中主要方法定义的规则是什么?
public class TestBed {
public TestBed() {
System.out.println("Test bed c'tor");
}
@SuppressWarnings("unused")
private static class Tester {
public static void main(String[] args) {
TestBed tb = new TestBed();
tb.f();
}
}
void f() {
System.out.println("TestBed::f()");
}
}
Run Code Online (Sandbox Code Playgroud) 我是Boost线程的新手,我不知道如何从多个线程执行输出.我有一个简单的boost :: thread从9倒数到1; 主线程等待然后打印"LiftOff .. !!"
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
struct callable {
void operator() ();
};
void callable::operator() () {
int i = 10;
while(--i > 0) {
cout << "#" << i << ", ";
boost::this_thread::yield();
}
cout.flush();
}
int main() {
callable x;
boost::thread myThread(x);
myThread.join();
cout << "LiftOff..!!" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是我必须在我的线程中使用显式的"cout.flush()"语句来显示输出.如果我不使用flush(),我只会得到"LiftOff !!" 作为输出.
有人可以告诉我为什么需要明确使用flush()吗?
我指的是std::is_member_function_pointer 这里可能的实现.
template< class T >
struct is_member_function_pointer_helper : std::false_type {};
template< class T, class U>
struct is_member_function_pointer_helper<T U::*> : std::is_function<T> {};
template< class T >
struct is_member_function_pointer : is_member_function_pointer_helper< std::remove_cv_t<T> >
#include <type_traits>
class A {
public:
void member() { }
};
int main()
{
// fails at compile time if A::member is a data member and not a function
static_assert(std::is_member_function_pointer<decltype(&A::member)>::value,
"A::member is not a member function.");
}
Run Code Online (Sandbox Code Playgroud)
我知道
"dectype(A ::构件)"
将会
"void(A ::*)()"
但我不明白什么类型T和类型U映射到"void(A ::*)()"?
我正在尝试使用测试库的静态版本来源构建.我有libtest.a和libtest.so可用,所以我使用"-static"选项.但是,看起来gcc链接器也试图搜索标准数学库的静态版本.知道我可以使用什么选项来链接标准库的共享版本吗?
g++ -static main.cpp -o a.out -L. -ltest
Run Code Online (Sandbox Code Playgroud)
错误:
/usr/bin/ld: cannot find -lm
Run Code Online (Sandbox Code Playgroud)