gpt4 book ai didi

c++ - 在 Visual Studio 中使用 C++ 类 - 未声明的标识符错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:42:05 24 4
gpt4 key购买 nike

<分区>

我希望这非常简单,但我终究无法找出问题所在。我是 C++ 的新手,我在 visual studio 中创建了一个 C++ 类,并试图在另一个文件的主要方法中使用它。我已经将所有内容都剥离到最低限度,但仍然无法运行。我得到的第一个编译错误是“测试”:未声明的标识符。如果我删除“测试测试;”从 App.cpp 可以很好地编译。下面是代码。有人可以帮忙吗?

应用程序.cpp:

#include "Test.h"
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

int main()
{
Test test;
//cout << test.getNumber() << endl;
return 0;
}

测试.h:

#pragma once
class Test
{
private:
int number;

public:
int getNumber();
Test();
~Test();
};

测试.cpp:

#include "stdafx.h"
#include "Test.h"


int Test::getNumber()
{
return number;
}

Test::Test()
{
this->number = 1;
}


Test::~Test()
{
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com