【发布时间】:2019-10-07 07:08:03
【问题描述】:
我正在 Microsoft Visual C++ 2010 Express 上编写程序,但我的类对象存在问题。我不断收到未声明的标识符并且缺少';'在标识符错误之前,我不确定是什么导致了问题。
我检查了我的标题是否有任何错误,并进行了一些更改,看看它是否能解决问题。
// RightJust class declaration that right justifies the numbers.
#ifdef RIGHTJUST_H_
#define RIGHTJUST_H_
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace System;
using namespace std;
class RightJust
{
private:
int x, totalWH1, totalWH2, totalWH3, totalWH4;
int itemT1, itemT2, itemT3, itemT4, itemT5; // Holds item totals
string WH1, WH2, WH3, WH4;
int num[4][5]; // Array containing data
public:
RightJust();
int warehouseLen();
void rightJustZero();
void rightJustLess();
};
// This program asks to user to choose a report type and displays
// the report type chosen.
#include "stdafx.h"
#include <iostream>
#include "RightJust.h"
#include <string>
#include <cstring>
using namespace System;
using namespace std;
int main
{
RightJust type;
if(reportType == 1)
{
type.rightJustZero();
}
else if(reportType == 2)
{
type.rightJustLess();
}
}
我只是想要一个解决方案来消除所有错误消息,以查看我的程序是否按照我需要的方式运行。
Test3.cpp
1>Test3.cpp(24): error C2065: 'RightJust' : undeclared identifier
1>Test3.cpp(24): error C2146: syntax error : missing ';' before identifier 'type'
1>Test3.cpp(24): error C2065: 'type' : undeclared identifier
1>Test3.cpp(27): error C2065: 'type' : undeclared identifier
1>Test3.cpp(27): error C2228: left of '.rightJustZero' must have class/struct/union
1> type is ''unknown-type''
1>Test3.cpp(31): error C2065: 'type' : undeclared identifier
1>Test3.cpp(31): error C2228: left of '.rightJustLess' must have class/struct/union
1> type is ''unknown-type''
【问题讨论】:
-
标题中缺少
#endif。 -
我不确定这些代码是否足以解决我的问题。如果它重现您的错误消息就足够了。
-
永远不要将
#include "stdafx.h"放在标题中。 -
欢迎来到 SO。阅读 How to Ask 和 minimal reproducible example 可能会有所帮助——MCVE 解释了你是如何知道这一点的:我不确定这是否足以找到解决我问题的代码
标签: c++