相关疑难解决方法(0)

错误:ISO C++禁止非const静态成员的类内初始化

这是头文件:employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <iostream>
#include <string>
using namespace std;

class Employee {
public:
    Employee(const string &first, const string &last) 
Run Code Online (Sandbox Code Playgroud)

重载的构造函数

    : firstName(first), 
Run Code Online (Sandbox Code Playgroud)

firstName重载的构造函数

      lastName(last) 
Run Code Online (Sandbox Code Playgroud)

lastName重载的构造函数

    { //The constructor start
    ++counter; 
Run Code Online (Sandbox Code Playgroud)

它为每个创建的对象增加一个加号;

    cout << "Employee constructor for " << firstName
         << ' ' << lastName << " called." << endl;
    }

    ~Employee() { 
Run Code Online (Sandbox Code Playgroud)

析构函数cout <<"~Workee()调用"<< firstName <<"<< lastName << endl;

返回每个对象的名和姓

        --counter; 
Run Code Online (Sandbox Code Playgroud)

反减一

    }

    string getFirstName() const {
        return firstName; 
    }

    string getLastName() const {
        return lastName;
    } …
Run Code Online (Sandbox Code Playgroud)

c++ standards static iso compiler-errors

17
推荐指数
2
解决办法
4万
查看次数

标签 统计

c++ ×1

compiler-errors ×1

iso ×1

standards ×1

static ×1