为什么我的类对象会导致未申报的标识符错误
Why is my class object causing undeclared identifier errors?
我正在在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''
标题中的包括后卫是错误的。应该是
#ifndef RIGHTJUST_H_
如果符号为未定义,则使用#ifdef RIGHTJUST_H_
会跳过代码。
您的.H文件中不应有#include "stdafx.h"
。而且,由于您似乎正在使用Visual Studio,因此您可以使用#pragma once
而不是Include Guard。
相关文章:
- 设置 Visual Studio for MPI: 找不到标识符错误
- 从子类访问模板类成员时出现"找不到标识符"错误
- 未声明的标识符错误,但变量定义正确 (?)
- 尝试使用类时获取标识符错误
- 我收到未声明的标识符错误,但我已包含头文件?
- 常量自动/标识符错误
- 为什么我的类对象会导致未申报的标识符错误
- C 未申报的标识符错误
- 在Visual Studio中使用C 类 - 未申报的标识符错误
- 编译器不喜欢我的类C++。获取未声明的标识符错误等
- 奇怪的未知标识符错误
- C 数组未申报的标识符错误
- 定义中未声明的标识符错误 C2065,显然存在
- 找不到标识符错误
- 稍后在程序中使用if-else构造内部声明的变量会导致未声明的标识符错误
- Xcode C++未声明的标识符错误
- 编译时未找到"log10"标识符错误
- 标识符错误之前缺少';' - 无法运行 MPI 示例
- 时间开始未找到标识符错误
- 声明项时出现未声明的标识符错误