簡體   English   中英

類實現文件中未聲明的標識符

[英]Undeclared identifier in class implementation file

Plorg.h:

#include <string>
    #ifndef PLORG_H
    #define PLORG_H

class Plorg{
private:
    string name;
    int CI;

public:
    Plorg();
    Plorg(const string & n,int x=50);
    ~Plorg();
    void ChangeID(int CIaux);
    void Report() const;
};  
#endif PLORG_H

Plorg.cpp:

#include <iostream>
#include <string>
#include "Plorg.h"

using namespace std;
Plorg::Plorg(){
    name="Plorga";
    CI=50;
};

Plorg::Plorg(const string & n,int CIaux=50){
    name=n;
    CI=CIaux;
};
void Plorg::ChangeID(int CIaux){
    CI=CIaux;
};

void Plorg::Report() const {
    cout << "My name is " << name << "!" <<endl;
    cout << "MY CI is" << CI << "." ;
};

Plorg::~Plorg(){
    cout << "Bye,human" ;
};

我得到這個錯誤,thoguh:

錯誤11錯誤C2065:'名稱':未聲明的標識符c:\\ users \\ work \\ documents \\ visual studio 2012 \\ projects \\ book \\ firstclass \\ firstclass \\ plorg.cpp 7 1 firstclass

所以我該怎么做?

string真的是std::string

class Plorg{
private:
    std::string name;
//  ^^^
public:
    Plorg();
    Plorg(const std::string& n, int x=50);
//              ^^^

順便說一句,您應該支持構造函數初始化列表,並且不要在實現中放入默認參數值:

Plorg::Plorg(const std::string & n, int CIaux) : name(n), CI(CIAux) {}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM