|
10鱼币
Arithmetic.h:
- #pragma once
- #ifndef _ARITHMETIC_
- #define _ARITHMETIC_
- #define __ARITHMETIC_API_BEGIN namespace api {
- #define __ARITHMETIC_API_END }
- #define _API api::
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #include <stack>
- __ARITHMETIC_API_BEGIN
- typedef void* idc_pointer;
- typedef AccountType account_type;
- typedef const Account const_acc, *const_acc_pointer;
- typedef const SubAccount const_subacc, *const_subacc_pointer;
- enum EventType
- {
- SystemEvent, // 系统消息
- OtherEvent, // 其他消息
- };
- enum AccountType
- {
- SYSTEM,
- ADMINISTRATOR,
- STANDARD_USER,
- BAN_USER,
- ALL_BAN_USER,
- };
- struct Event
- {
- EventType event_type;
- std::wstring event;
- };
- class IDC
- {
- private:
- const char id[18];
- const char key;
- };
- class Account
- {
- public:
- Account(void) = default;
- ~Account(void) = default;
- std::wstring name; // 昵称
- static void* operator new(size_t size); // 重 载 //
- static void operator delete(void* pointer); // 运算符 //
- static void* operator new[](size_t size); // 函 数 //
- static void operator delete[](void* pointer); // new and delete //
- template <idc_pointer* idc>
- Account operator +(const_acc acc);
- template <idc_pointer* idc>
- Account operator -(const_acc acc);
- protected:
- long long int uid; // 用户 ID
- private:
- unsigned long long int score = 0;
- unsigned long long int exp = 0;
- std::stack <Event> event_stack;
- account_type acc_type = STANDARD_USER;
- friend std::wostream& operator <<(std::wostream& wos, const_acc acc);
- friend std::wistream& operator >>(std::wistream& wis, const_acc acc);
- };
- class SubAccount : public Account
- {
- public:
- SubAccount(void) = default;
- ~SubAccount(void) = default;
- private:
- unsigned long long int sub_uid; // 子用户 ID
- };
- __ARITHMETIC_API_END
- #endif
复制代码
Arithmetic.cpp:
- #include "Arithmetic.h"
- __ARITHMETIC_API_BEGIN
- void* Account::operator new(size_t size)
- {
- return malloc(size);
- }
- void Account::operator delete(void* pointer)
- {
- free(pointer);
- }
- void* Account::operator new[](size_t size)
- {
- return malloc(size);
- }
- void Account::operator delete[](void* pointer)
- {
- free(pointer);
- }
- template <bool printEvent = false>
- std::wostream& operator<<(std::wostream& wos, const_acc acc)
- {
- return wos;
- }
- template <bool inputLevel = false>
- std::wistream& operator>>(std::wistream& wis, const_acc acc)
- {
- return wis;
- }
- template <idc_pointer* idc>
- Account Account::operator-(const_acc)
- {
- return Account();
- }
- __ARITHMETIC_API_END
复制代码
main.cpp:
- #include "Arithmetic.h"
- int main(int argc, char *argv[])
- {
- api::Account* current = new api::Account;
- std::wcout << L"--- 欢迎使用口算APP ---" << std::endl;
- std::wcout << L"-- - 请输入操作-- - " << std::endl;
- std::wcout << L"1. XXX" << std::endl;
- return 0;
- }
复制代码
编译器返回:
- 已启动生成...
- 1>------ 已启动生成: 项目: 口算APP - Console, 配置: Debug x64 ------
- 1>Arithmetic.cpp
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(18,39): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(18,27): error C2146: 语法错误: 缺少“;”(在标识符“account_type”的前面)
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,27): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,27): error C2146: 语法错误: 缺少“;”(在标识符“const_acc”的前面)
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,36): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,59): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,27): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,27): error C2146: 语法错误: 缺少“;”(在标识符“const_subacc”的前面)
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,39): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,62): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(28,6): error C2371: “api::AccountType”: 重定义;不同的基类型
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(18,15): message : 参见“api::AccountType”的声明
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(50,7): error C2371: “api::Account”: 重定义;不同的基类型
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,15): message : 参见“api::Account”的声明
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(84,7): error C2371: “api::SubAccount”: 重定义;不同的基类型
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,15): message : 参见“api::SubAccount”的声明
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(5,7): error C2825: 'api::Account': 当后面跟“::”时必须为类或命名空间
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(5,16): error C2510: “Account”:“::”的左边必须是类/结构/联合
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(10,6): error C2825: 'api::Account': 当后面跟“::”时必须为类或命名空间
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(10,15): error C2510: “Account”:“::”的左边必须是类/结构/联合
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(15,7): error C2825: 'api::Account': 当后面跟“::”时必须为类或命名空间
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(15,16): error C2510: “Account”:“::”的左边必须是类/结构/联合
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(20,6): error C2825: 'api::Account': 当后面跟“::”时必须为类或命名空间
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(20,15): error C2510: “Account”:“::”的左边必须是类/结构/联合
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(26,47): error C2061: 语法错误: 标识符“const_acc”
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(26,16): error C2805: 二进制“operator <<”的参数太少
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(32,47): error C2061: 语法错误: 标识符“const_acc”
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(32,16): error C2805: 二进制“operator >>”的参数太少
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(38,9): error C2825: 'api::Account': 当后面跟“::”时必须为类或命名空间
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(38,18): error C2510: “Account”:“::”的左边必须是类/结构/联合
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.cpp(39,1): error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
- 1>main.cpp
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(18,39): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(18,27): error C2146: 语法错误: 缺少“;”(在标识符“account_type”的前面)
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,27): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,27): error C2146: 语法错误: 缺少“;”(在标识符“const_acc”的前面)
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,36): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,59): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,27): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,27): error C2146: 语法错误: 缺少“;”(在标识符“const_subacc”的前面)
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,39): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,62): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(28,6): error C2371: “api::AccountType”: 重定义;不同的基类型
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(18,15): message : 参见“api::AccountType”的声明
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(50,7): error C2371: “api::Account”: 重定义;不同的基类型
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(19,15): message : 参见“api::Account”的声明
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(84,7): error C2371: “api::SubAccount”: 重定义;不同的基类型
- 1>F:\私人\C++\Program\Console\口算APP - Console\Arithmetic.h(20,15): message : 参见“api::SubAccount”的声明
- 1>F:\私人\C++\Program\Console\口算APP - Console\main.cpp(5,26): error C2737: “api::Account”: 必须初始化 const 对象
- 1>正在生成代码...
- 1>已完成生成项目“口算APP - Console.vcxproj”的操作 - 失败。
- ========== 生成: 0 成功,1 失败,0 最新,0 已跳过 ==========
- ========= 生成 开始于 10:35 AM,并花费了 01.050 秒 ==========
复制代码
求助!
主要是 Arithmetic.h 的问题,因为 typedef 的位置不对,所以就报错了:
- #pragma once
- #ifndef _ARITHMETIC_
- #define _ARITHMETIC_
- #define __ARITHMETIC_API_BEGIN namespace api {
- #define __ARITHMETIC_API_END }
- #define _API api::
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #include <stack>
- __ARITHMETIC_API_BEGIN
- typedef void* idc_pointer;
- enum EventType
- {
- SystemEvent, // 系统消息
- OtherEvent, // 其他消息
- };
- enum AccountType
- {
- SYSTEM,
- ADMINISTRATOR,
- STANDARD_USER,
- BAN_USER,
- ALL_BAN_USER,
- };
- typedef AccountType account_type;
- struct Event
- {
- EventType event_type;
- std::wstring event;
- };
- class IDC
- {
- private:
- const char id[18];
- const char key;
- };
- class Account
- {
- public:
- Account(void) = default;
- ~Account(void) = default;
- std::wstring name; // 昵称
-
- static void* operator new(size_t size); // 重 载 //
- static void operator delete(void* pointer); // 运算符 //
- static void* operator new[](size_t size); // 函 数 //
- static void operator delete[](void* pointer); // new and delete //
- template <idc_pointer* idc>
- Account operator +(Account acc);
- template <idc_pointer* idc>
- Account operator -(Account acc);
- protected:
- long long int uid; // 用户 ID
- private:
- unsigned long long int score = 0;
- unsigned long long int exp = 0;
- std::stack <Event> event_stack;
- account_type acc_type = STANDARD_USER;
- friend std::wostream& operator <<(std::wostream& wos, Account acc);
- friend std::wistream& operator >>(std::wistream& wis, Account acc);
- };
- typedef const Account const_acc, *const_acc_pointer;
- class SubAccount : public Account
- {
- public:
- SubAccount(void) = default;
- ~SubAccount(void) = default;
- private:
- unsigned long long int sub_uid; // 子用户 ID
- };
- typedef const SubAccount const_subacc, *const_subacc_pointer;
- __ARITHMETIC_API_END
- #endif
复制代码
另外,你的 new,delete 等运算没有写呢
|
最佳答案
查看完整内容
主要是 Arithmetic.h 的问题,因为 typedef 的位置不对,所以就报错了:
另外,你的 new,delete 等运算没有写呢
|