在')'令牌之前需要不合格ID? [英] Expected unqualified-id before ')' token?

查看:70
本文介绍了在')'令牌之前需要不合格ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个基类,并在默认构造函数中的初始化列表出现错误.这是我遇到的错误:

I want to create a base class and get an error with my initializer list in default constructor. Here are the errors I'm getting:

giasuc.cpp:3:8: error: expected unqualified-id before ')' token
 GiaSuc(): ten(""), soConSinh(0), soLitSua(0) {
        ^
giasuc.cpp:6:14: error: expected ')' before '&' token
 GiaSuc(GiaSuc& mGiasuc): ten(mGiasuc.ten), soConSinh(mGiasuc.soConSinh), soLitS
ua(mGiasuc.soLitSua) {
              ^
giasuc.cpp:9:20: error: expected ')' before '&' token
 GiaSuc(std::string &mTen, short mSoCon = 0, short mLitSua = 0): ten(mTen), soCo
nSinh(mSoCon), soLitSua(mLitSua) {
                    ^

这是我正在建立的课程( giasuc.h ):

And this is the class I am building (giasuc.h):

#ifndef GIA_SUC_H
#define GIA_SUC_H

#include <iostream>
#include <string>

class GiaSuc {
protected:
    std::string ten;
    short soConSinh;
    short soLitSua;

public:
    GiaSuc();
    GiaSuc(GiaSuc& mGiasuc);
    GiaSuc(std::string &mTen, short mSoCon, short mLitSua);
    virtual void keu() = 0;
    virtual ~GiaSuc() = 0;
};

#endif // GIA_SUC_H

giasuc.cpp :

#include "giasuc.h"
#include <string>
GiaSuc(): ten(""), soConSinh(0), soLitSua(0) {
}

GiaSuc(GiaSuc& mGiasuc): ten(mGiasuc.ten), soConSinh(mGiasuc.soConSinh), soLitSua(mGiasuc.soLitSua) {
}

GiaSuc(std::string &mTen, short mSoCon = 0, short mLitSua = 0): ten(mTen), soConSinh(mSoCon), soLitSua(mLitSua) {
}

我正在使用MinGW g ++(GCC)4.9.3,并将其编译为:

I am using MinGW g++ (GCC) 4.9.3, and compiling it with:

g ++ -Wall -Wpedantic -Weffc ++ -ansi -c giasuc.cpp

推荐答案

在类定义之外定义类的成员函数时,需要使用范围运算符 :: 和类名告诉编译器它们属于什么类.

When you define member functions of a class outside the class definition, you need to use the scope operator :: and the class name to tell the compiler what class they belong to.

喜欢

GiaSuc::GiaSuc(): ten(""), soConSinh(0), soLitSua(0) { ... }

这篇关于在')'令牌之前需要不合格ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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