Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Teensy 3的新位置 我在一个“.h”文件中定义的ARDUION/TENSEY环境中有一个C++类。在“.cpp”文件中,我尝试使用一些代码来执行“placement new”。我得到以下错误: oscillator.h:17: error: no matching function for call to 'operator new(sizetype, AudioSynthWaveform*)' _current_tone = static_cast<AudioStream*>(new (&_waveform) AudioSynthWaveform); ^ /tmp/build578ae2c22656d87e9d0d68db21416349.tmp/sketch/oscillator.h:17:68: note: candidate is: In file included from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Printable.h:25:0, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Print.h:39, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Stream.h:24, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/HardwareSerial.h:169, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/WProgram.h:16, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Arduino.h:1, from /tmp/build578ae2c22656d87e9d0d68db21416349.tmp/sketch/Synthesizer.ino.cpp:1: /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h:12:8: note: void* operator new(size_t) void * operator new(size_t size); ^ /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h:12:8: note: candidate expects 1 argument, 2 provided exit status 1 no matching function for call to 'operator new(sizetype, AudioSynthWaveform*)'_C++_Arduino_Embedded_Placement New_Teensy - Fatal编程技术网

使用Teensy 3的新位置 我在一个“.h”文件中定义的ARDUION/TENSEY环境中有一个C++类。在“.cpp”文件中,我尝试使用一些代码来执行“placement new”。我得到以下错误: oscillator.h:17: error: no matching function for call to 'operator new(sizetype, AudioSynthWaveform*)' _current_tone = static_cast<AudioStream*>(new (&_waveform) AudioSynthWaveform); ^ /tmp/build578ae2c22656d87e9d0d68db21416349.tmp/sketch/oscillator.h:17:68: note: candidate is: In file included from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Printable.h:25:0, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Print.h:39, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Stream.h:24, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/HardwareSerial.h:169, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/WProgram.h:16, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Arduino.h:1, from /tmp/build578ae2c22656d87e9d0d68db21416349.tmp/sketch/Synthesizer.ino.cpp:1: /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h:12:8: note: void* operator new(size_t) void * operator new(size_t size); ^ /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h:12:8: note: candidate expects 1 argument, 2 provided exit status 1 no matching function for call to 'operator new(sizetype, AudioSynthWaveform*)'

使用Teensy 3的新位置 我在一个“.h”文件中定义的ARDUION/TENSEY环境中有一个C++类。在“.cpp”文件中,我尝试使用一些代码来执行“placement new”。我得到以下错误: oscillator.h:17: error: no matching function for call to 'operator new(sizetype, AudioSynthWaveform*)' _current_tone = static_cast<AudioStream*>(new (&_waveform) AudioSynthWaveform); ^ /tmp/build578ae2c22656d87e9d0d68db21416349.tmp/sketch/oscillator.h:17:68: note: candidate is: In file included from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Printable.h:25:0, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Print.h:39, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Stream.h:24, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/HardwareSerial.h:169, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/WProgram.h:16, from /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/Arduino.h:1, from /tmp/build578ae2c22656d87e9d0d68db21416349.tmp/sketch/Synthesizer.ino.cpp:1: /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h:12:8: note: void* operator new(size_t) void * operator new(size_t size); ^ /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h:12:8: note: candidate expects 1 argument, 2 provided exit status 1 no matching function for call to 'operator new(sizetype, AudioSynthWaveform*)',c++,arduino,embedded,placement-new,teensy,C++,Arduino,Embedded,Placement New,Teensy,这似乎可行,但前提是我在头文件中的方法中使用placement new。如果我将代码移出头并移到“.cpp”实现文件中,我会得到一个类似的错误,即只需要一个参数 有办法解决这个问题吗?我发现解决这个问题最直接的方法就是打开 /opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h 然后把原型 void *operator new(size_t size, void *ptr); void operator delete(void *

这似乎可行,但前提是我在头文件中的方法中使用placement new。如果我将代码移出头并移到“.cpp”实现文件中,我会得到一个类似的错误,即只需要一个参数


有办法解决这个问题吗?

我发现解决这个问题最直接的方法就是打开

/opt/arduino-1.6.7/hardware/teensy/avr/cores/teensy3/new.h
然后把原型

void *operator new(size_t size, void *ptr);

void operator delete(void *obj, void *alloc);
有多个重载操作符,然后重载关联的“.cpp”文件中的函数


不确定为什么没有包括在开头…

静态\u cast
是可疑的,如果在标题中有,您的操作员new/delete需要是内联的。(我认为它们应该只在cpp文件中)。@Jarod42我之所以这么做,是因为有几个不同的类派生自AudioStream,我想将它们向上转换到它们的父类,所以在我定义的类中,我只需要保留一个指向它们所在缓冲区的指针(AudioStream类型),与其为每种类型保留一个单独的指针和一组逻辑来确定从“new”返回的指针应该放在哪里,基本上问题是,在我使用的库中,“AudioStream”类中,只有流的“update”函数被声明为“virtual”,所以,如果我要为“AudioStream”的所有子类存储一个指向超类的指针,我相信每次我想调用一个方法而不是它的一个子类的方法时,我都必须向下转换指针。你知道为什么要这样做吗?什么是
(波形
)以及它是如何初始化的?正如这个问题的公认答案所示:(波形是私有变量部分中union中AudioStream子类的一种类型,然后我使用以下((当前音调是AudioStream类型的指针)):
(当前音调=静态)(&_波形)音频合成波形);
void *operator new(size_t size, void *ptr);

void operator delete(void *obj, void *alloc);