【问题标题】:Visual C++ Express: fmin and fmax identifier not found?Visual C++ Express:找不到 fmin 和 fmax 标识符?
【发布时间】:2013-10-07 20:49:03
【问题描述】:

我已经在 Mac 上编译了这段代码,所以我知道没有语法错误,但是,在 VC++ Express 2010 中,我收到一个错误,提示找不到 fmin 和 fmax 标识符。我安装了 Windows SDK 7.1 看看是否可以修复它,但它什么也没做:/

#include "DigitalDistortion.h"
#include "IPlug_include_in_plug_src.h"
#include "IControl.h"
#include "resource.h"

const int kNumPrograms = 1;

enum EParams
{
  kThreshold = 0,
  kNumParams
};

enum ELayout
{
  kWidth = GUI_WIDTH,
  kHeight = GUI_HEIGHT,

  kThresholdX = 100,
  kThresholdY = 100,
  kKnobFrames = 60
};

DigitalDistortion::DigitalDistortion(IPlugInstanceInfo instanceInfo)
  :     IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mThreshold(1.)
{
  TRACE;

  //arguments are: name, defaultVal, minVal, maxVal, step, label
  GetParam(kThreshold)->InitDouble("Threshold", 100., 0.01, 100.0, 0.01, "%");
  GetParam(kThreshold)->SetShape(2.);

  IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);
  pGraphics->AttachPanelBackground(&COLOR_RED);

  IBitmap knob = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, kKnobFrames);

  pGraphics->AttachControl(new IKnobMultiControl(this, kThresholdX, kThresholdY,         kThreshold, &knob));

  AttachGraphics(pGraphics);

  //MakePreset("preset 1", ... );
  MakeDefaultPreset((char *) "-", kNumPrograms);
}

DigitalDistortion::~DigitalDistortion() {}

void DigitalDistortion::ProcessDoubleReplacing(
    double** inputs,
    double** outputs,
    int nFrames)
{
  // Mutex is already locked for us.

  int const channelCount = 2;

  for (int i = 0; i < channelCount; i++) {
    double* input = inputs[i];
    double* output = outputs[i];

    for (int s = 0; s < nFrames; ++s, ++input, ++output) {
      if(*input >= 0) {
        // Make sure positive values can't go above the threshold:
        *output = fmin(*input, mThreshold);
      } else {
        // Make sure negative values can't go below the threshold:
        *output = fmax(*input, -mThreshold);
      }
      *output /= mThreshold;
    }
  }
}

void DigitalDistortion::Reset()
{
  TRACE;
  IMutexLock lock(this);
}

void DigitalDistortion::OnParamChange(int paramIdx)
{
  IMutexLock lock(this);

  switch (paramIdx)
  {
    case kThreshold:
      mThreshold = GetParam(kThreshold)->Value() / 100.;
      break;

    default:
      break;
  }
}

【问题讨论】:

  • 好吧,您尝试使用来自cmath 库的fminfmax?为什么不包含标题?
  • 我在快速谷歌搜索后确实包含了标题,但它仍然返回错误。
  • 因为需要写std::fmin/std::fmax或者使用namespace std
  • 错误:命名空间“std”没有成员“fmin”。不过我修好了。一旦我包含了算法头,std::min 就起作用了。

标签: c++ visual-studio-2010 compiler-errors identifier


【解决方案1】:

fminfmax 是 C99 功能。 Visual Studio 只实现了 C89 标准,所以没有那个功能。

【讨论】:

    【解决方案2】:

    由于它是 C++,您可以(而且,我敢说,应该)使用 &lt;algorithm&gt; 标头中的 std::minstd::max 函数。

    这些是函数模板,因此它们将接受定义了比较运算符的任何类型。只要确保两个参数的类型相同,否则它可能无法编译。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 2017-03-25
      • 1970-01-01
      相关资源
      最近更新 更多