【问题标题】:Compiler error: does not name a type编译器错误:未命名类型
【发布时间】:2012-01-07 13:30:00
【问题描述】:

我是 C++ 新手,我通常可以找出错误并找出问题所在,但我很困惑。

我收到一条错误消息“line|10|error: 'string' in class 'mine' does not name a type”

这是我的.h:

#ifndef MINE_H
#define MINE_H
#include <iostream>
#include <string>

using namespace std;

class mine
{

public:
mine();
string getName();

};

#endif // MINE_H

这是我的.cpp:

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

using namespace std;
mine::mine()
{
    //ctor
}

mine::string getName()
{

}

【问题讨论】:

  • 请不要使用using namespace
  • 并且从不(ab)在头文件中使用namespace std

标签: c++ string types


【解决方案1】:
mine::string getName()
{

} 

应该是

string mine::getName()
{

} 

【讨论】:

    【解决方案2】:

    应该是:

    string mine::getName()
    {
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-05
      • 2014-04-17
      相关资源
      最近更新 更多