小编Sta*_*aro的帖子

包括来自不同目录的头文件?

我正在研究一个项目,我一直都不知道如何从不同的目录导入文件.以下是我的一些文件的组织方式:

-stdafx.h
-core/
-->renderer.cpp
-shapes/
-->sphere.h
-->sphere.cpp
Run Code Online (Sandbox Code Playgroud)

我如何访问stdafx.hshapes/sphere.hcore/renderer.cpp

c++ include

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

正确的方法来分配和释放指向数组的指针

我想创建一个指向3个浮点数组的指针数组.这样做的正确方法是什么?

float *array1[SIZE]; // I think it is automatically allocated
// OR
float **array1 = calloc(SIZE, sizeof(float*));
free(array1);

for (int i = 0; i < SIZE; i++) {
    array1[i] = (float[]){0,0,0};
    // OR
    array1[i] = calloc(3, sizeof(float));
}
Run Code Online (Sandbox Code Playgroud)

那么我将如何释放数据呢?我很确定只是free(array1);不行,所以我会释放数组中的每个指针然后释放数组,或者因为我分配了三个浮点数,我会释放每个浮点数,然后每个3浮点数组,然后整个数组? ?

c arrays pointers

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

是否可以在类外声明Objective-C方法?

我知道你可以在类之外声明一个C函数,但是可以在类之外声明一个Objective-C方法吗?

例:

// Works
void printHelloC()
{
    NSLog(@"Hello.");
}

// Error
-(void) printHelloOC
{
    NSLog(@"Hello.");
}

int main (int argc, const char * argv[])
{
    @autoreleasepool {
        printHelloC();
        [self printHelloOC];// 'self' obviously would not work but you get the idea
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c methods objective-c

10
推荐指数
2
解决办法
6089
查看次数

对指针进行类型转换?

是否可以键入一个数组?

我有一组向量函数,它都接受指向float的指针,float是一个由三个浮点数组成的数组.我可以使用typedef float*vec3_t,但它不会让我创建一个对象,只需将其设置为括号中的数组即可.

typedef float* vec3_t;

vec3_t a = {1,1,1}; // Does not work
vec3_t b = (float[]){1,1,1}; // Works
float c[] = {1,1,1}; // Works

void f(vec3_t x);

f({1,1,1}); // Error
f((float[]){1,1,1}; // OK
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么这种方式有效吗?

c arrays pointers

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

malloc +自动引用计数?

如果我使用malloc和自动引用计数,我还需要手动释放内存吗?

int a[100];
int *b = malloc(sizeof(int) * 100);
free(b);
Run Code Online (Sandbox Code Playgroud)

malloc objective-c automatic-ref-counting

9
推荐指数
2
解决办法
6985
查看次数

Safari Javascript控制台自动滚动

是否有可能使Safari 6中的JavaScript控制台自动向下滚动以显示最新的日志?目前,我每次登录时都必须手动向下滚动.

javascript debugging safari console

9
推荐指数
0
解决办法
380
查看次数

检查是否设置了哪个算法更快?

我正在制作一个游戏,其中我将大量数据存储在一个整数或长整数中,因为我将拥有大量数据.出于性能原因,我不想使用整个类,并且不需要它们.我找到了两种从整数中检索一位的方法.我想知道是否有人知道我应该使用哪一个或哪一个更快.

方法:

return (integer & (1 << bit)) != 0;

return (integer >> bit& 0x1) == 1;

java algorithm optimization bit-manipulation

7
推荐指数
2
解决办法
4375
查看次数

非常小的数字

我正在写一个Mandelbrot观众.一切正常,除非你得到一个非常高的变焦,图像开始像大约缩放10 ^( - 14)像素.我在猜测,因为我的双vars中的内存耗尽.我能用什么才能使用非常小的数字?

我需要使用java.lang.Math类,我不认为它支持bigdecimal

java

6
推荐指数
2
解决办法
3454
查看次数

没有以前的原型?

可能重复:
错误:没有以前的函数原型.为什么我收到此错误?

我有一个函数,我在头文件中原型,但Xcode仍然给我警告No previous prototype for the function 'printBind'.我setBind以相同的方式使用函数原型,但在我的实现中我没有收到此函数的警告.

CelGL.h

#ifndef Under_Siege_CelGL_h
#define Under_Siege_CelGL_h

void setBind(int input);
void printBind();

#endif
Run Code Online (Sandbox Code Playgroud)

CelGL.c

#include <stdio.h>
#include "CelGL.h"

int bind;

void setBind(int bindin) { // No warning here?
    bind = bindin;
}

void printBind() { // Warning here
    printf("%i", bind);
}
Run Code Online (Sandbox Code Playgroud)

c xcode function

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

听取键/鼠事件

是否可以在没有用户选择gui的情况下监听键和鼠标事件?我想制作一个在没有gui的情况下在后台运行的程序,并响应用户交互,例如按下ctrl-t.

java swing keylistener mouselistener

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