【问题标题】:KnapSack Branch & Bound weird compiling errorsKnapSack Branch and Bound 奇怪的编译错误
【发布时间】:2014-03-18 17:28:02
【问题描述】:

所以我正在使用分支定界算法来实现 KnapSack 问题。我已经完成了它的实现,但是我遇到了一些奇怪的编译错误,我不知道如何解决:

编译错误

gcc -Wall -pedantic -g -std=c99   -c -o bnb.o bnb.c
bnb.c: In function ‘branch_and_bound’:
bnb.c:225: warning: cast from pointer to integer of different size
bnb.c:229: warning: implicit declaration of function ‘copy_string’
bnb.c:248: warning: cast from pointer to integer of different size
bnb.c:251: error: ‘struc_sol’ has no member named ‘string’
bnb.c:260: error: ‘struc_sol’ has no member named ‘string’
bnb.c:260: warning: cast from pointer to integer of different size
bnb.c:263: error: ‘struc_sol’ has no member named ‘string’
make: *** [bnb.o] Error 1

关于我做错了什么有什么建议吗?

【问题讨论】:

  • 哪个错误信息你不明白?
  • 请提供一个最小的例子。我不倾向于通过 300 多行代码
  • 对每个单独的错误进行简短的 Google 搜索应该可以让您大致了解问题所在以及需要解决的问题。如果您在理解特定问题时遇到问题,请删除部分代码,直到只剩下该错误,然后将其发布在问题中。

标签: c algorithm compilation compiler-errors knapsack-problem


【解决方案1】:

bnb.c:225:警告:从指针转换为不同大小的整数

这是从这条线:

     topNode->solution_vec[i] = (int)malloc(sizeof(int));

正如消息中提到的,malloc() 返回一个指针。您不应该将其转换为整数。实际上,您根本不需要为solution_vec[i] 分配内存,因为它已经由topNode 的早期分配分配了。


bnb.c:229:警告:函数‘copy_string’的隐式声明

检查您的头文件中是否声明了copy_string()


bnb.c:251: 错误:‘struc_sol’没有名为‘string’的成员

正如它所提到的,struc_sol 没有名为string 的成员,因此child1Node->string 会导致语法错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 2016-01-23
    • 2010-10-07
    • 1970-01-01
    相关资源
    最近更新 更多