使用类作为向量类型时出错 - "Undeclared identifier"
ERROR using a class as a vector type - "Undeclared identifier"
你好堆栈溢出!
我遇到了一个我试图解决但没有成功的问题,因此我转向您希望得到答案的程序员。
我怀疑这个问题的是,它与我的 main.cpp 有关,由于原因,我尚未开始编码。可能是非常错误的。
任何提示/提示都会受到赞赏!
错误是在库存标题中的该部分
// Vector
static std::vector<accounts> users;
错误消息在底部列出。
我包含了两个类标题文件。
main.cpp:
// Classes
#include "BankFunctions.h" // Handles the bank functions
#include "accounts.h" // Handles the customer accounts
// Libraries
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <Windows.h>
#include <sstream>
int main() {
return 0;
}
类:帐户
标题:
#pragma once
// Libraries
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <Windows.h>
#include <sstream>
// Classes
#include "BankFunctions.h"
class accounts
{
public:
// Constructor
accounts(
unsigned int newId,
unsigned int newAge,
unsigned int newSSN,
std::string newFirstName,
std::string newLastName,
std::string newAdress,
std::string newEmail,
double newBalance
);
// Overload constructor
accounts(std::string eId, std::string eNAge, std::string eSSN, std::string eFName, std::string eLName, std::string eEmail, std::string eAdress, std::string eNBalance);
// Mutators
inline void setId(unsigned int i) { id = i; }
inline void setAge(unsigned int a) { age = a; }
inline void setSSN(unsigned int ssn) { SSN = ssn; }
inline void setFirstName(std::string FN) { firstName = FN; }
inline void setLastName(std::string LN) { lastName = LN; }
inline void setEmail(std::string em) { email = em; }
inline void setAdress(std::string adr) { adress = adr; }
inline void setBalance(double newBalance, bool t);
// Accessors
inline unsigned int getId() const { return id; }
inline unsigned int getAge() const { return age; }
inline unsigned int getSSN() const { return SSN; }
inline std::string getFirstName() const { return firstName; }
inline std::string getLastName() const { return lastName; }
inline std::string getEmail() const { return email; }
inline std::string getAdress() const { return adress; }
inline double getBalance() const { return balance; }
private:
// Customer account details
unsigned int id;
unsigned int age;
unsigned int SSN; // Social Security Number
std::string firstName;
std::string lastName;
std::string adress;
std::string email;
double balance;
};
类2:BankFunctions
标题:
#pragma once
// Libraries
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <Windows.h>
#include <sstream>
// Classes
#include "accounts.h"
class BankFunctions
{
public:
BankFunctions();
static void loadVector(); // Loads in customer account information into objects that get stored into a vector. (All the existing accounts get loaded in)
static void newCustomer(); // Create new customer account
static void existingCustomer(); // View customer account
static void deposit(unsigned int accId); // Deposit money function
static void withdraw(unsigned int accId); // Withdraw money function
// Edit customer account
static void editCustomerDetails(unsigned int accId);
// Related Functions
static void editAge(unsigned int accId);
static void editSSN(unsigned int accId);
static void editFirstName(unsigned int accId);
static void editLastName(unsigned int accId);
static void editAdress(unsigned int accId);
static void editEmail(unsigned int accId);
static void editBalance(unsigned int accId);
private:
// Vector
static std::vector<accounts> users;
static unsigned int amountOfAccounts;
};
错误消息:
...bankfunctions.h(36): error C2065: 'accounts': undeclared identifier
...bankfunctions.h(36): error C2923: 'std::vector': 'accounts' is not a valid template type argument for parameter '_Ty'
...bankfunctions.h(36): error C3203: 'allocator': unspecialized class template can't be used as a template argument for template parameter '_Alloc', expected a real type
尝试从帐户中删除 include BankFunctions.h
我认为,问题是,在其中包含完成的位置的整个标题文件中,请简单地插入整个标头文件,但是pragma once
确保您不会将标题不包括在CPP文件中。当您的标题彼此包含时,可以将accounts
的类定义超过bankfunctions的第36行。
您也可以在main.cpp的最顶部放置一个额外的class accounts;
。这也应该起作用,但不是一个漂亮的解决方案。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- 这个函数哪里出错了
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 为重写std::exception的库生成swig接口时出错
- 导入/导出变量时出错
- 使用类作为向量类型时出错 - "Undeclared identifier"