小编alg*_*uru的帖子

如何使用Git更新我的项目版本号?

说我有两个分支:developfeature.

假设我还有一个名为的文件VersionNumber,其中包含以下内容:

BUILD_NUMBER 1

我想用Git的挂钩,这样,当我合并featuredevelop,在BUILD_NUMBER现场就会自动增加.

我想到了使用post-merge钩子的以下过程:

  1. 检查正在合并的分支是 develop
  2. VersionNumber通过递增BUILD_NUMBER1来更新文件
  3. 添加更新的文件: git add VersionNumber
  4. 修改提交: git commit --amend -C HEAD --no-verify

一切正常,直到最后的命令.Git说我不能在合并过程中修改提交(这对我来说很惊讶,因为我认为这是post-merge).

关于我如何做到这一点的任何建议(使用post-merge或任何其他钩子)?

git automation version-numbering githooks

7
推荐指数
1
解决办法
310
查看次数

可以在"堆栈"上分配的向量从函数传递到函数吗?

我知道当函数完成执行时,在函数的堆栈上分配的变量变得不可访问.但是,无论分配方式如何,矢量类型都会在堆上分配它们的元素.所以,例如,

vector<int> A;
Run Code Online (Sandbox Code Playgroud)

将为堆上的元素而不是堆栈分配空间.

我的问题是,假设我有以下代码:

int main(int argc, char *argv[]) {
    // initialize a vector
    vector<int> A = initVector(100000);

    // do something with the vector...

    return 0;
}


// initialize the vector
vector<int> initVector(int size) {
    vector<int> A (size);  // initialize the vector "on the stack"

    // fill the vector with a sequence of numbers...
    int counter = 0;
    for (vector<int>::iterator i = A.begin(); i != A.end(); i++) {
        (*i) = counter++;
    }

    return A;
}
Run Code Online (Sandbox Code Playgroud)

在main函数中使用向量A时,是否会出现内存访问问题?我试了好几次,他们都正常工作,但我很害怕这可能只是运气.

我看到它的方式是,向量A在堆上分配它的元素,但它有一些"开销"参数(可能是向量的大小)在堆栈本身上分配.因此,如果这些参数被另一个分配覆盖,则在main函数中使用向量可能会导致内存访问问题.有任何想法吗?

c++ memory-management vector

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

算法:将一组元素分成两组的所有可能方法?

我在集合 U 中有 n 个元素(假设由大小为 n 的数组表示)。我想找到所有可能的方法将集合 U 分成两个集合 A 和 B,其中 |A| + |B| = n。

例如,如果 U = {a,b,c,d},组合将是:

  1. A = {a} -- B = {b,c,d}
  2. A = {b} -- B = {a,c,d}
  3. A = {c} -- B = {a,b,d}
  4. A = {d} -- B = {a,b,c}
  5. A = {a,b} -- B = {c,d}
  6. A = {a,c} -- B = {b,d}
  7. A = {a,d} -- B = {b,c}

请注意,以下两种情况被视为相等,只应计算一种:

情况 1:A = {a,b} -- B = {c,d}

情况 …

algorithm combinations set

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

从另一个文件调用 C++ 函数时出现“未定义符号”

我有两组文件:PolynomialArithmetic.h/cpp 和 Options.h/cpp

Options.h 定义为:

// Options.h

#ifndef Options_h
#define Options_h

#define BINARY_HEAP 0

inline int chosenHeap ();


#endif
Run Code Online (Sandbox Code Playgroud)

Options.cpp定义为:

// Options.cpp

#include "Options.h"

inline int chosenHeap() { return BINARY_HEAP; }
Run Code Online (Sandbox Code Playgroud)

PolynomialArithmetic.cpp 包含以下内容:

// PolynomialArithmetic.cpp

#include "PolynomialArithmetic.h"
#include "Options.h"

void foo () {
...
    if (chosenHeap() == BINARY_HEAP) {
        // DO SOMETHING
    }
...
}
Run Code Online (Sandbox Code Playgroud)

当我编译时,我收到错误:

Undefined symbols for architecture x86_64:
    "chosenHeap()", referenced from: foo() in PolynomialArithmetic.o
Run Code Online (Sandbox Code Playgroud)

我猜测这是某种链接错误。这是我编译代码的方式:

# Makefile

# some configs
....

main: Options.o PolynomialArithmetic.o
    $(CXX) $(CXXFLAGS) $(CPPFLAGS) …
Run Code Online (Sandbox Code Playgroud)

c++ linker symbols makefile undefined

0
推荐指数
1
解决办法
1416
查看次数