小编Car*_*ing的帖子

C中的OOP,隐式传递self作为参数

我一直在研究一个在C中学习OOP的例子.目前我已经提出了这个有效的代码,但是我有兴趣让这些方法隐式地将self作为参数传递.

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
//#include "Stopwatch.h"


typedef struct stopwatch_s
{
    unsigned int milliseconds;
    unsigned int seconds;
    unsigned int minutes;
    unsigned int hours;

    bool is_enabled;

    void ( *tick )      ( struct stopwatch_s* );
    void ( *start )     ( struct stopwatch_s* );
    void ( *stop )      ( struct stopwatch_s* );
    void ( *reset )     ( struct stopwatch_s* );
} stopwatch_t;

static void tick (stopwatch_t* _self)
{
    stopwatch_t * self = _self;
    if (self->is_enabled)
    {
        self->milliseconds++;
        if (self->milliseconds >= 1000) …
Run Code Online (Sandbox Code Playgroud)

c oop

16
推荐指数
4
解决办法
4164
查看次数

如何正确设置TravisCI对于一个简单的C项目

我正在尝试设置TravisCI在C项目上为我做自动构建和测试.

为了让我学习和理解它,我做了一个示例github repo,使其在将其移动到我的最终项目之前工作.

我的项目基本上包含3个文件:

.travis.yml:

language: C
Run Code Online (Sandbox Code Playgroud)

生成文件:

hellomake: main.c
    gcc -o hellomake main.c -I.
Run Code Online (Sandbox Code Playgroud)

main.c中:

#include <stdio.h>

void main() 
{
    printf("Hello World!");
}
Run Code Online (Sandbox Code Playgroud)

由于该项目现在我在Travis中收到以下错误:

0.00s$ ./configure && make && make test
/home/travis/build.sh: line 41: ./configure: No such file or directory
The command "./configure && make && make test" exited with 127.
Run Code Online (Sandbox Code Playgroud)

我错过了什么或做错了什么?

c makefile travis-ci

13
推荐指数
1
解决办法
4961
查看次数

如何将值传递给AngularJS $ http然后回调

我的问题与这里的问题非常相似:如何将值传递给AngularJS $ http成功回调

根据Angular.js

$ http遗留承诺方法成功和错误已被弃用.请改用标准方法.

那么怎么样,只用.then做类似的事情呢?

在我的服务中,我的代码是碎片式的

fetchFromAPI: function(key) {
    return $http.jsonp(...); 
}
Run Code Online (Sandbox Code Playgroud)

这是我的控制者

for (var i = 0; i < units.length; i++){
    Service.fetchFromAPI(i)
    .then(function(response) {
        console.log(i);
    }, function(response) {
        console.log(response);
    });
}
Run Code Online (Sandbox Code Playgroud)

但是由于在返回任何调用之前的for循环完成执行,控制台的输出是相同的数字,我无法绕过上面编写类似于.success示例的上述内容,我的所有尝试都给了我我的控制器不是函数的错误.

Jim Horng发布的解决方案是

$http.get('/plugin/' + key + '/js').success((function(key) {
     return function(data) {
        console.log(key, data);
    }
})(key));
Run Code Online (Sandbox Code Playgroud)

javascript callback angularjs

4
推荐指数
1
解决办法
1593
查看次数

标签 统计

c ×2

angularjs ×1

callback ×1

javascript ×1

makefile ×1

oop ×1

travis-ci ×1