繁体   English   中英

linux ubuntu c++.h和.cpp文件

[英]linux ubuntu c++ .h and .cpp file

我有一个 my.h 文件:

#ifndef __MY__
#define __MY__

#include <string>
#include <time.h>

class S
{
    public: S();
    std::string myname;
};

#endif

我的.cpp

#include "my.h";

#include<string>
#include<iostream>

using namespace std;

S::S()
{
    // .. code
}

我想创建一个so文件。 创建时没有错误。 但是当我编译.h文件时它说:字符串:没有这样的文件或目录。 如果我 pus string.h 而不是 string 我有错误:在 my.h 中的 S(在 class S)之前,预期的'=',',',';','asm'。 在.cpp 文件中(如果我用string.h 更改字符串)我在编译后出现错误:命名空间std 中的字符串没有命名类型。 我哪里错了?

尝试这个

#ifndef MY_H
#define MY_H
#include <string>
#include <time.h>

class S
{
public: S();
std::string myname;
};

#endif



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

using namespace std;

S::S()
{
    //code
}

好吧,首先,您似乎来自 java 因为当您键入时:

class S
{
  public: S();
  std::string myname;
};

我猜你的意思是:

class S
{
  public:

    S();

  private:

    std::string myname;
};

.cpp文件中,您输入了s而不是S :请注意,C++ 对于类名称是区分大小写的。

另外,关于您的问题,我怀疑您当前使用的是C编译器,而不是C++编译器。 在不知道使用的命令行的情况下,我不能说更多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM