Visual Studio中的c ++类和命名空间错误

时间:2018-03-08 02:47:44

标签: c++ class

我通常在Linux上用c ++编程,但最近我开始学习游戏黑客,所以我开始在visual studio中创建我的程序。我对c ++相对较新,在本学期开始学习它。我一直得到:" Hello不是类或命名空间名称。"我从我的linux vm中获取了一个工作程序并在Visual Studio中使用它并且仍然遇到了同样的错误。

我的代码如下:

#pragma once

#ifndef HELLO_H
#define HELLO_H

#include "stdafx.h"
#include <Windows.h>
#include <string>
#include <iostream>

class Hello {
    public:
        Hello();
        void setString(std::string w);
        void print();
    private:
        std::string word;
};

#endif // !1






#include "Hello.h"
#include "stdafx.h"

Hello::Hello() {
    word = "hello world";
}

void Hello::setString(std::string w) {
    word = w;
}

void Hello::print() {
    std::cout << word << std::endl;
}






// HelloWorld.cpp : Defines the entry point for the console application.
//
#include "Hello.h"
#include "stdafx.h"


int main()
{
    Hello* word = new Hello();
    word->print();
    word->setString("test");
    word->print();
    system("pause");
    return 0;
}

0 个答案:

没有答案