在c++11编译器中有一个额外的限定错误
Having problems with an extra qualification error in c++11 compiler
我是一名c++11学生,我遇到了一个额外的资格错误。
我在一个。h文件中声明了一个类,在一个单独的。cpp文件中实现了一个布尔函数。
类定义如下:
class Order{
std::string customer, product;
std::vector<std::string> itemList;
bool validName(std::string name);
bool isCustomerName(std::string name);
bool isProductName(std::string name);
bool isItemName(std::string name);
public:
Order(std::vector<std::string> line);
void print(){
void graph(std::ofstream os);
};//class Order
所有的函数都在一个单独的cpp文件中实现,并且我以以下方式定义了所有函数的作用域:
Order::Order(std::vector<std::string> line){
或
bool Order::isCustomerName(std::string name){
当我尝试编译cpp文件时,出现以下错误:
error: extra qualification ‘Order::’ on member ‘Order’ [-fpermissive]
查找后,这似乎是与在同一函数的类定义中使用作用域操作符或某种双重使用作用域操作符有关的错误。
我没有将cpp文件中的实现封装在单独的命名空间中,并且只包含了cpp文件的相应.h文件。有没有人能给我一点提示,告诉我解决这个问题的方向?
感谢这是cpp文件的顶部:
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include "order.h"
这是来自同一个cpp的一个示例函数:
bool Order::isProductName(std::string name){
if (name.size() > 0 && isalpha(name[0]))
return true;
return false; }
上面列出的类定义实际上是类Order. h中的所有内容。
.h的顶部是:
#pragma once
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include "util.h"
在你的类中有这样一行:
void print(){
我相信你是指
void print();
由于c++编译的方式,当您说#include "order.h"
时,编译器实际上是将order.h的内容复制并粘贴到cpp文件中。因此,它看到您已经为print打开了这个函数定义,并在成员函数print (gcc扩展)中声明了一些局部函数,然后您最终在标记为};//class Order
的行关闭了该函数。这看起来像是类定义的结束,但实际上是函数的结束。后面在cpp文件中的函数定义被视为在类体内部,这会混淆编译器。
相关文章:
- C++11 中好友模板类的视觉C++错误
- 我将 Makefile 更改为 C++11 版本,但仍然收到列表初始值设定项错误
- C++ Visual Studio 错误:名称后跟'::'必须是类或命名空间名称 (DirectX 11)
- 使用 C++11 时列表中出现编译错误
- main.cpp(11):错误 C2059:语法错误:"字符串"
- C++ 分段错误:11 错误,同时编码将两个数字相加的链接列表
- 分割错误 11:尝试使用 cin 输入 B[1] 时
- 外部函数在 main() 上调用时返回分段错误 11.(C++)
- C++ 11 Boost 1.65 recursive_directory_iterator给出分段错误
- 在 centos 7 上编译 Qt 5.11.1 中的错误
- 覆盖 iostream <<会导致错误 - C++ 11
- 树实现给出分段错误(核心转储)错误 c++ 11
- 奇怪的错误C++ 11 模板类
- CMAKE错误:C 11不支持Mac High Sierra
- Visual Studio 2015 c++ 项目错误 c++11 标准
- Clang++ 非静态数据成员初始化错误?C++11.
- 简单C++代码上的运行时错误信号11
- 指向类方法错误c++11的指针数组
- Coderunner 2 -初始化列表错误- c++ 11
- C++ 分段错误:11,试图使操作员过载<<