- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道这里有很多类似的问题,但是我无法解决这个问题,也没有同事,所以:
我正在使用 MinGW (4.8.x) 和 Eclipse CDT Kepler。
1) 我有自己的代码,为了清理它,我将其更改为使用结构 vector - 一切都很好,除了接收它的函数提示“参数无效”。
2) 我将我的代码减少到一个最小的工作示例,如果我将它全部放在一个文件中它可以工作,但是如果我将我的定义移到标题中(我需要在我的主代码中做)它突然无法解析结构中的字段...下面的代码是针对三个文件的配置,header/function/main。
(在我的主要代码中,我使用 namespace std
- 但这似乎不是问题所在。此外,这里有一个最小工作示例的无关 header ,但是它们在我的主要代码。)
我的标题.h
/*************************/
/****** myheaders.h ******/
/*************************/
/**-- Header Files --**/
// File Streams and IO
#include <stdio.h>
#include <sstream>
#include <iostream>
#include <fstream>
// For strtod -> string to double
#include <stdlib.h>
// Math Operations
//#include <math.h>
#include <cmath>
// To get the CPU time
#include <time.h>
// For Vectors
#include <vector>
// For strings, C strings right now...
#include <cstring>
// Needed globally for the function definitions
// using namespace std;
#ifndef MY_HEADERS
#define MY_HEADERS
struct SpeciesLoss {
int ReactionID;
int SpeciesID;
double coefficient;
};
std::vector< double > SpeciesLossRate(std::vector<SpeciesLoss> , int, const std::vector< double > & );
#endif
函数.cpp
/*************************/
/****** function.cpp *****/
/*************************/
#include "myheaders.h"
std::vector< double > SpeciesLossRate(
std::vector< SpeciesLoss > SpeciesLossList,
int Number_Species,
const std::vector< double >& Combined_Rates
)
{
std::vector< double > temp_species_loss;
temp_species_loss.resize(1);
temp_species_loss[0]=SpeciesLossList[0].ReactionID;
return temp_species_loss;
}
主要.cpp
/*************************/
/******** main.cpp *******/
/*************************/
#include "myheaders.h"
std::vector< SpeciesLoss > SpeciesLossAll; // New vector for recording species loss, uses a vector of structs
int main(int argc, char* argv[])
{
std::vector< double > Rates;
Rates.push_back(1);
SpeciesLossAll.push_back(SpeciesLoss());
SpeciesLossAll[0].ReactionID = 0;
SpeciesLossAll[0].SpeciesID = 0;
SpeciesLossAll[0].coefficient = 0;
std::vector< double > SpeciesConcentrationChange = SpeciesLossRate(SpeciesLossAll,1, Rates);
return 0;
}
编辑:
截图
编辑 2:有趣的更新——它在 Linux 上用 GCC 编译得很好。总比没有好,但我仍然想知道出了什么问题,而且我希望我的代码是跨平台的...
编辑 3:这越来越奇怪了——我刚刚在运行 Windows 7 的家用 PC 上测试了我的代码(在 Linux 上编译的完整项目),在我的笔记本电脑运行 Windows 8 时它构建良好,但问题出现了。C++ 构建的设置完全相同。两者都运行 MinGW 4.8.1 ...两者都运行最新的 Eclipse Kepler...
是的,我知道我仍然需要测试一些建议。
最佳答案
#ifndef MY_HEADERS
#define MY_HEADERS
应该在文件的开头。由于您不知道编译器将以什么顺序包含 header ,这可能会导致问题...特别是如果您将个人 header 包含在多个文件中,这肯定会使它表现得像这样。另外,请记住,由于您没有提供默认构造函数,而是使用编译器为您提供的构造函数,因此结构中的那些变量很可能不会像您期望的那样被初始化为零。
编辑#1您是否编译了所有内容,而不仅仅是主要...我只是将您的代码复制到 VS 中并且可以正常工作!
编辑#2尝试定义内联函数而不是单独的实现文件。
static std::vector< double > SpeciesLossRate(
std::vector< SpeciesLoss > SpeciesLossList,
int Number_Species,
const std::vector< double >& Combined_Rates
)
{
std::vector< double > temp_species_loss;
temp_species_loss.resize(1);
temp_species_loss[0]=SpeciesLossList[0].ReactionID;
return temp_species_loss;
}
编辑#3好的,从屏幕截图来看,这绝对是有效的代码。为了尝试一切;实现您自己的构造函数和结构的复制构造函数。我知道这听起来可能很愚蠢,但也许 Eclipse 不这么认为。
关于c++ - 另一个 : Passing Vector of Structs to Function - C++, MinGW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20949295/
或者存在像 这样的指针和引用C ? 我正在尝试开始使用 vala,但很高兴知道 vala 是“按引用传递”还是“按值传递” 最佳答案 首先你应该明白默认的vala编译器valac编译为 C(作为一种中
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我确实对 crypt() PHP 函数感到困惑。 当第二个 crypt 显然使用不同的第二个参数时,以下两个 crypt 函数如何给出相同的输出?差异盐意味着差异哈希对吗? echo crypt("p
我正在尝试在方案中模拟堆栈。我正在使用 DrScheme 并选择语言 R5RS。我需要创建 pop、push 和 peek 的函数。但我无法弄清楚如何通过引用传递。我已经阅读了一些关于盒子的信息,但是
我已经查过维基百科并用 google 搜索过,但我仍然无法理解 ALGOL 60 中的按名称传递的工作原理。 最佳答案 我在 Pass-By-Name Parameter Passing 找到了很好的
问题:我想知道在 Excel 2003 VBA 中处理数组的最佳解决方案是什么 背景:我在 Excel 2003 中有一个超过 5000 行的宏。我在过去 2 年中构建了它,将新功能添加为新过程,这有
我正在尝试反转位图数组,而不修改源数组。但问题是源数组也被颠倒了。我做错了什么还是我应该以其他方式做?感谢您的帮助。 private GalleryAdapter galleryAdapter; pr
因此,关于按引用传递/按值传递,方法如何处理参数传递已有详细记录,但是变量赋值又如何呢? 例如,我刚刚编写了一些如下所示的代码: TreeNode parent = null; TreeNode cu
我正在编写一个脚本,它将从我们的星号系统中回填调用详细记录到我们的 MySQL 日志数据库中。在下面的代码中,我试图忽略重复键并继续到下一行,但是当这段代码执行时,我所看到的只是第一行欺骗警告,然后脚
我从一个 Action (executeProcess)重定向到另一个(executeIndex)。我希望能够不使用GET传递参数/变量(例如$this->redirect('index', arra
我经常看到方法接口(interface)的两种相互冲突的策略,大致概括如下: // Form 1: Pass in an object. double calculateTaxesOwed(TaxFo
目前正在学习回调在 JavaScript 中的含义,我正在努力理解回调是如何工作的,以及术语“passing this”或“passing that”的来源以及它如何与回调一起工作?我想展示一些示例代
我通过 URL 传递参数并且页面被正确重定向。如何访问下一个(重定向的)页面上(从上一页)传递并在 URL 中可用的参数?谁能告诉我该怎么做? 或者有没有其他的方式在页面之间传递参数? 是否有类似 A
我通过 URL 传递参数并且页面被正确重定向。如何访问下一个(重定向的)页面上(从上一页)传递并在 URL 中可用的参数?谁能告诉我该怎么做? 或者有没有其他的方式在页面之间传递参数? 是否有类似 A
按引用传递和按名称传递的参数传递模式有什么区别这里是 Python 中的一个示例,但假设我们不使用任何 Python 规则: def P(x,y) global i y=1 prin
我正在编写自己的 LLVM pass,它修改了 LLVM 位码。在生成位码时,我想禁用函数内联,但是当我完成对位码的修改后,我想调用执行函数内联的传递。这个可以吗。如果是,如何? 为了更好地理解我在说
我有一个模板函数,负责将模板值写入流。它看起来像这样: template void Write( T value, std::ostream& stream, endianness_t endian
我一直在使用两个程序 llvm 的 opt 和 clifford wolf 的 yosys两者都有类似的通行证接口(interface)。(他们使用共享库作为优化 passes ) 我想根据我的 ll
在我们使用引用传递的 C++ 中,我们引用了我们从参数传递给函数参数的地址,它本质上是一个指针,对吗?因此,虽然它们本质上是相同的东西,别名和所有,但指针不也需要内存空间吗?因此,无论我们在参数函数中
这是一个关于 64 位整数的效率问题。假设我不需要修改“int”参数的值,我应该通过值还是引用传递它。 假设是 32 位机: 1) 32 位 int:我猜答案是“按值传递”,因为“按引用传递”会产生额
我是一名优秀的程序员,十分优秀!