我是使用eclipse cdt的新手.我有一个makefile项目,在我的Makefile中有两个以上的目标.说Makefile如下,
all:
...
t1:
...
t2:
...
Run Code Online (Sandbox Code Playgroud)
CDT构建目标"全部"很容易.但是,如何构建除第一个之外的目标,如t1和t2?谢谢.
我的位置可以大大提高我的代码的清晰度和维护需求.
我正在寻找的是这样的:
#define MY_MACRO(arg) #if (arg)>0 cout<<((arg)*5.0)<<endl; #else cout<<((arg)/5.0)<<endl; #endif
Run Code Online (Sandbox Code Playgroud)
这里的想法:
预处理器根据宏参数的编译时(常量)值替换不同的代码行.当然,我知道这种语法不起作用,因为它#被视为string-ize运算符而不是标准#if,但我认为这证明了我试图实现的预处理器功能.
我知道我可以if在那里放一个标准语句,然后编译器/运行时将检查该值.但是这对于应用程序来说是不必要的工作,当arg总是传递一个常量值时,10.8或者-12.5只需要在编译时进行评估.
这个数字运算应用程序的性能需求要求尽可能消除所有不必要的运行时条件,并且已经使用了许多常量值和宏(代替变量和函数)来实现这一点.在不必将预处理器代码与实际if条件混合的情况下继续这种趋势的能力将使这更加清晰 - 当然,代码清洁是使用宏时最大的问题之一,尤其是在这个级别.
我猜它在Android中的轻量级通知称为Toast,因为它们像烤面包机一样弹出.有人可以证实这一点或提供更好的解释吗?我正在教授关于Android开发的课程,并希望编辑维基,所以我想确保它正确.
我在Java中实现了一个非常简单的ConnectionPool.它没有花哨的功能,只是获取/释放连接方法.
我该如何测试它是否有效?
我知道有很多连接池可以在那里使用,它比我要做的更可靠,但我只是想练习理解连接池的工作方式.
谢谢!
这是代码,以防它有帮助:
public class ConnectionPoolImpl implements ConnectionPool {
private Vector<PooledConnection> connections; // The connections container
String url;
String username;
String password;
/**
* Instanciates a new MySQLConnectionPool
* @param nbConnectionsMax
*/
public ConnectionPoolImpl(String DBUrl, String username, String password){
this.connections = new Vector<PooledConnection>();
this.url = DBUrl;
this.username = username;
this.password = password;
}
/**
* Returns a connection from the pool, if some are available, or create a new one.
*
* @return the connection.
*/
public Connection …Run Code Online (Sandbox Code Playgroud) java testing integration-testing unit-testing connection-pooling
为什么这段代码会返回"class java.lang.Object"?
Object a = new Object() {
public Object b = new Object(){
public int c;
};
};
System.out.println(a.getClass().getField("b").getType());
Run Code Online (Sandbox Code Playgroud)
为什么内在类型会丢失?我怎样才能反映c场?
编辑:
这个有效(正如在一些答案中指出的那样):
a.getClass().getField("b").get(a) ...
Run Code Online (Sandbox Code Playgroud)
但是我必须调用一个getter,有没有办法用反射元数据反映c?
考虑以下代码:
#define F(x, ...) X = x and VA_ARGS = __VA_ARGS__
#define G(...) F(__VA_ARGS__)
F(1, 2, 3)
G(1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
X = 1 and VA_ARGS = 2, 3两个宏的预期输出,这就是我用GCC得到的,但是,MSVC将其扩展为:
X = 1 and VA_ARGS = 2, 3
X = 1, 2, 3 and VA_ARGS =
Run Code Online (Sandbox Code Playgroud)
也就是说,__VA_ARGS__将其扩展为单个参数,而不是分解为多个参数.
有什么方法吗?
我正在尝试使用属性类型Date之一保存托管对象managedObjectContext.
代码如下:
reminder.eventDate = selectedDate;
NSLog(@"Date: %@", selectedDate);
NSError *error = nil;
if (![reminder.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
Run Code Online (Sandbox Code Playgroud)
在上下文保存程序中使用SIGABRT崩溃.这是一个控制台日志:
2011-02-28 00:50:18.817 MyApp[9021:207] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSDate isEqualToString:]:
unrecognized selector sent to instance 0x4e73490'
*** Call stack at first throw:
(
0 CoreFoundation 0x01057be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x011ac5c2 objc_exception_throw + 47
2 CoreFoundation 0x010596fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00fc9366 ___forwarding___ + 966 … 我收到语法错误"insert}以完成ClassBody.
此代码正常/无错误:
import java.awt.Rectangle;
class Trigger
{
Type type;
long time;
ObjectID controlType;
int controlNum;
int resType, resNum;
Rectangle location;
enum Type {TIMED, CONTROLED, LOCATION, RESOURCE};
Trigger()
{
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我添加像这样的构造函数时,我收到错误:
class Trigger
{
Type type;
long time;
ObjectID controlType;
int controlNum;
int resType, resNum;
Rectangle location;
enum Type {TIMED, CONTROLED, LOCATION, RESOURCE}; //I get the error on this line
Trigger(Type.TIMED, long t)
{
time = t;
}
Trigger(Type.CONTROLLED, int c)
{
controlNum= c;
}
Trigger(Type.LOCATION, int locx, int locy, …Run Code Online (Sandbox Code Playgroud) 我们希望创建一个couchdb数据库的定期备份,以便在异地发货.什么是最不具侵入性的方法来获得这些 - 理想情况下,不会中断或显着降低现有数据库服务器的性能?
说,我有一个包含30个元素的1d数组:
array1d[0] = 1
array1d[1] = 2
array1d[2] = 3
.
.
.
array1[29] = 30
Run Code Online (Sandbox Code Playgroud)
如何将1d数组转换为2d数组?
说10x3?
array2d[0][0] = 1 array2d[0][1] =2 array2d[0][2] =3
.
.
.
array2d[9][0] = 28 array2d[9][1] =29 array2d[9][2] =30
Run Code Online (Sandbox Code Playgroud)
我应该使用for循环吗?
但我无法解决这个问题.
java ×4
android ×1
arrays ×1
awt ×1
backup ×1
c++ ×1
conditional ×1
core-data ×1
couchdb ×1
eclipse ×1
ios ×1
iphone ×1
makefile ×1
objective-c ×1
processing ×1
reflection ×1
substitution ×1
testing ×1
toast ×1
unit-testing ×1
visual-c++ ×1