期望字符串常量之前的非限定id [英] expected unqualified-id before string constant

查看:2382
本文介绍了期望字符串常量之前的非限定id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个C ++应用程序,它实现了一个与math.h结合的振荡器。我的代码应该可以正常工作(尝试编译一个目标文件),但是我得到的编译器错误很可能与语法/ etc有关;我认为这与名称空间有关。错误:

终端输出:

 用户名 -  Macbook -Pro:合成器部件用户名$ make 
g ++ -o Oscillators.o -c -I。 Oscillators.cpp -c
在Oscillators.cpp中包含的文件中:2:
/usr/include/math.h:41:错误:期望字符串常量之前的非限定id
在包含的文件中来自/usr/include/c++/4.2.1/bits/locale_facets.tcc:42,来自/usr/include/c++/4.2.1/locale:46的
,来自/ usr / include / c ++ / 4.2.1 / bits / ostream.tcc:46,/usr/include/c++/4.2.1/ostream:635中的
,/usr/include/c++/4.2.1/中的
iostream:45,来自Oscillators.cpp的
:4:
/usr/include/c++/4.2.1/typeinfo:41:错误:行结束前的预期声明
make:** * [Oscillators.o] Error 1

Oscillators.cpp

  #includeOscillators.h
#include
#include< vector>
#include< iostream>

#define TWOPI(6.2831853072)

using namespace std;

振荡器(int srate = 44100,int tabsize = 8192,double freq = 200)//默认输出200Hz正弦波
{
if(srate< = 0) {
cout<< 错误:采样率必须为正值<< ENDL;
return;
}
sizeovrsr_ =(double)tabsize /(double)srate $ b $ if(freq <20 || freq> 20000){
cout < 错误:频率超出可听范围<< ENDL;
return;
}
curfreq_ = freq;
curphase_ = 0.0 //超出一个,超出制表大小
incr_ = curfreq * sizeovrsr_;
for(int i = 0; i< tabize; i ++){
gtable.push_back(sin((i * TWOPI)/(double)tabsize));
}
gtable.push_back(gtable [0]);
}

void print_table()
{
vector< double> :: size_type i;
for(i = 0; i cout<< gtable [i]<< \\\
;
cout<< ENDL;
}

Oscillators.h

  #ifndef GUARD_OSCILLATORS_H 
#define GUARD_OSCILLATORS_H
#include< vector>

类振荡器{
public:
/ *
void fill_sine(); //将表改为正弦波
void fill_square(); //将表格改为方波
void fill_sawtooth(); //将表改为锯齿波
void fill_triangle(); //将表改为三角波
双击(双频); //将输出当前样本并更新阶段
* /
void print_table(); //将打印所有表值到标准输出
振荡器(int srate = 44100,double freq = 200,int tabsize = 8192);
私人:
double sizeovrsr_; //将在初始化时设置,并将确定相位增加tickc func
double curphase_;
double curfreq_; //如果发送到打勾功能的频率与当前打勾不匹配,它将被重置;
double incr_;
std :: vector< double> gtable_; //将包含带保护点的波表。
}
#endif

我见过其他一些提到使用g ++的建议-Wall -g,但我不确定那是什么问题,并且这里还有别的事情发生。



任何帮助都将非常感谢!谢谢!!

解决方案

这是一个简单的问题。 strong>您只是在头文件末尾忘记了分号。



编译器错误是因为在结尾处丢失了分号类定义很难与实际问题相关联 - 只要养成了在创建类后出现错误时检查的习惯。


I'm currently writing a C++ application which implements an Oscillator in conjuction with math.h. The code I have should work fine for the application (trying to compile an object file), bu I'm getting a compiler error most likely having to do with syntax/etc; I think it has something to do with namespace. The error:

Terminal Output:

User-Name-Macbook-Pro:Synth Parts UserName$ make
g++ -o Oscillators.o -c -I. Oscillators.cpp -c
In file included from Oscillators.cpp:2:
/usr/include/math.h:41: error: expected unqualified-id before string constant
In file included from /usr/include/c++/4.2.1/bits/locale_facets.tcc:42,
             from /usr/include/c++/4.2.1/locale:46,
             from /usr/include/c++/4.2.1/bits/ostream.tcc:46,
             from /usr/include/c++/4.2.1/ostream:635,
             from /usr/include/c++/4.2.1/iostream:45,
             from Oscillators.cpp:4:
/usr/include/c++/4.2.1/typeinfo:41: error: expected declaration before end of line
make: *** [Oscillators.o] Error 1

Oscillators.cpp

#include "Oscillators.h"
#include <math.h>
#include <vector>
#include <iostream>

#define TWOPI (6.2831853072)

using namespace std;

oscillator(int srate = 44100, int tabsize = 8192, double freq = 200) // Default to output 200Hz Sine Wave
{
    if(srate <= 0) {
        cout << "Error: sample rate must be positive" << endl;
        return;
    }
    sizeovrsr_ = (double)tabsize / (double)srate
    if(freq < 20 || freq > 20000) {
        cout << "Error: frequency is out of audible range" << endl;
        return;
    }
    curfreq_ = freq;
    curphase_ = 0.0 // Not out of one, out of tabsize
    incr_ = curfreq * sizeovrsr_;
    for(int i = 0; i < tabsize; i++) {
        gtable.push_back(sin((i*TWOPI)/(double)tabsize));
    }
    gtable.push_back(gtable[0]);
}

void print_table()
{
    vector<double>::size_type i;
    for(i = 0; i < gtable.size(); i++)
        cout << gtable[i] << "\n";
    cout << endl;
}

Oscillators.h

#ifndef GUARD_OSCILLATORS_H
#define GUARD_OSCILLATORS_H
#include <vector>

class oscillator {
public:
    /*
    void fill_sine(); // Will change the table to a sine wave
    void fill_square(); // Will change the table to a square wave
    void fill_sawtooth(); // Will change the table to a sawtooth wave
    void fill_triangle(); // Will change the table to a triangle wave
    double tick(double freq); // Will output the current sample and update the phase
    */
    void print_table(); // Will print all table values to standard output
    oscillator(int srate = 44100, double freq = 200, int tabsize = 8192);
private:
    double sizeovrsr_; // Will be set at initialization and will determine phase increase for tick func
    double curphase_;
    double curfreq_; // if the freq sent to a tick function doesn't match the current tick, it will be reset;
    double incr_;
    std::vector<double> gtable_; // Will contain a wavetable with a guard point.
}
#endif

I've seen other suggestions that mention using g++ -Wall -g but I'm not sure that that is the problem, and that there is something else going on here.

Any help would be much appreciated! Thanks!!

解决方案

This is a simple problem.

You just forgot the semi colon at the end of your header file.

The compiler errors you get for missing the semi colon at the end of a class definition are very hard to relate to the actual problem - just get in the habit of checking that when you get errors after you create a class.

这篇关于期望字符串常量之前的非限定id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆