错误:expected constructor, destructor, or type conversion before ‘typedef’ 的解决方法

错误现象:

Compiling TradeData.cpp
/home/dev/mobsys/payServer/include/config.h:35: 错误:expected constructor, destructor, or type conversion before ‘typedef’
/home/dev/mobsys/payServer/include/config.h:60: 错误:expected constructor, destructor, or type conversion before ‘;’ token
make[1]: *** [/home/dev/mobsys/payServer/obj/payServer/TradeData.o] 错误 1
make[1]: Leaving directory `/home/dev/mobsys/payServer/src'

 

源文件:

TradeData.cpp

 

/**
 * 交易数据的序列化处理
 * ============================================================================
 * 版权所有 (C) 2008 覃学涵,并保留所有权利。
 * 网站地址: http://www.tnc.com.cn
 * ============================================================================
 * @author:     qinhan <qinxuehan@tnc.com.cn>
 * @version:    v1.0
 * ---------------------------------------------
 * $Author: qinhan $
 * $Date: 2009-05-18 15:59:12 +0800 (星期一) $
 * $Id: TradeData.h  qinhan $
*/

#ifndef _TradeData_h_
#define _TradeData_h_


#include "config.h"

/*交易指令结构体*/
class TradeData {

public: 

 
 CT_STRUCT value;


 
 TradeData(CT_STRUCT * _value)
 {
  memset(&value,0,sizeof(value));
  memcpy(&value,_value,sizeof(value));
 }

 TradeData()
 {
  memset(&value,0,sizeof(value));
 }

 //序列化对象
 std::string serialize();


 //把字符串解释称结构体
 bool TradeData::unserialize(std::string str);
 
};


#endif

 

 

原因:config.h里面的USING_PTYPES 没包含ptypes头文件所致。

a.cpp:56:3: error: conflicting declaration ‘typedef struct HTNode HTNode’ 56 | } HTNode, *HuffmanTree; | ^~~~~~ a.cpp:10:3: note: previous declaration as ‘typedef struct HTNode HTNode’ 10 | } HTNode, *HuffmanTree; | ^~~~~~ a.cpp:56:12: error: conflicting declaration ‘typedef struct HTNode* HuffmanTree’ 56 | } HTNode, *HuffmanTree; | ^~~~~~~~~~~ a.cpp:10:12: note: previous declaration as ‘typedef struct HTNode* HuffmanTree’ 10 | } HTNode, *HuffmanTree; | ^~~~~~~~~~~ a.cpp:154:5: error: redefinition of ‘int main()’ 154 | int main() { | ^~~~ a.cpp:16:5: note: ‘int main()’ previously defined here 16 | int main() { | ^~~~ a.cpp:195:9: error: expected constructor, destructor, or type conversion before ‘=’ token 195 | *HT = (HuffmanTree)malloc((m + 1) * sizeof(HTNode)); | ^ a.cpp:196:5: error: expected unqualified-id before ‘if’ 196 | if (*HT == NULL) { | ^~ a.cpp:200:5: error: expected unqualified-id before ‘for’ 200 | for (int i = 1; i <= n; i++) { | ^~~ a.cpp:200:21: error: ‘i’ does not name a type 200 | for (int i = 1; i <= n; i++) { | ^ a.cpp:200:29: error: ‘i’ does not name a type 200 | for (int i = 1; i <= n; i++) { | ^ a.cpp:206:5: error: expected unqualified-id before ‘for’ 206 | for (int i = n + 1; i <= m; i++) { | ^~~ a.cpp:206:25: error: ‘i’ does not name a type 206 | for (int i = n + 1; i <= m; i++) { | ^ a.cpp:206:33: error: ‘i’ does not name a type 206 | for (int i = n + 1; i <= m; i++) { | ^ a.cpp:212:5: error: expected unqualified-id before ‘for’ 212 | for (int i = n + 1; i <= m; i++) { | ^~~ a.cpp:212:25: error: ‘i’ does not name a type 212 | for (int i = n + 1; i <= m; i++) { | ^ a.cpp:212:33: error: ‘i’ does not name a type 212 | for (int i = n + 1; i <= m; i++) { | ^ a.cpp:222:9: error: expected constructor, destructor, or type conversion before ‘=’ token 222 | *HC = (HuffmanCode)malloc((n + 1) * sizeof(char *)); | ^ a.cpp:223:5: error: expected unqualified-id before ‘if’ 223 | if (*HC == NULL) { | ^~ a.cpp:228:31: error: ‘n’ was not declared in this scope 228 | char *cd = (char *)malloc(n * sizeof(char)); | ^ a.cpp:229:5: error: expected unqualified-id before ‘if’ 229 | if (cd == NULL) { | ^~ a.cpp:235:5: error: ‘cd’ does not name a type 235 | cd[n - 1] = '\0'; | ^~ a.cpp:236:5: error: expected unqualified-id before ‘for’ 236 | for (int i = 1; i <= n; i++) { | ^~~ a.cpp:236:21: error: ‘i’ does not name a type 236 | for (int i = 1; i <= n; i++) { | ^ a.cpp:236:29: error: ‘i’ does not name a type 236 | for (int i = 1; i <= n; i++) { | ^ a.cpp:260:9: error: expected constructor, destructor, or type conversion before ‘(’ token 260 | free(cd); | ^ a.cpp:261:1: error: expected declaration before ‘}’ token 261 | } | ^ a.cpp:263:5: error: redefinition of ‘int main()’ 263 | int main() { | ^~~~ a.cpp:16:5: note: ‘int main()’ previously defined here 16 | int main() { | ^~~~ a.cpp:304:15: error: ‘i’ was not declared in this scope 304 | (*HT)[i].weight = (*HT)[s1].weight + (*HT)[s2].weight; | ^ a.cpp:304:17: error: expected constructor, destructor, or type conversion before ‘.’ token 304 | (*HT)[i].weight = (*HT)[s1].weight + (*HT)[s2].weight; | ^ a.cpp:305:5: error: expected declaration before ‘}’ token 305 | } | ^ a.cpp:307:9: error: expected constructor, destructor, or type conversion before ‘=’ token 307 | *HC = (HuffmanCode)malloc((n + 1) * sizeof(char *)); | ^ a.cpp:308:11: error: redefinition of ‘char* cd’ 308 | char *cd = (char *)malloc(n * sizeof(char)); | ^~ a.cpp:228:11: note: ‘char* cd’ previously defined here 228 | char *cd = (char *)malloc(n * sizeof(char)); | ^~ a.cpp:308:31: error: ‘n’ was not declared in this scope 308 | char *cd = (char *)malloc(n * sizeof(char)); | ^ a.cpp:309:5: error: ‘cd’ does not name a type 309 | cd[n - 1] = '\0'; | ^~ a.cpp:310:5: error: expected unqualified-id before ‘for’ 310 | for (int i = 1; i <= n; i++) { | ^~~ a.cpp:310:21: error: ‘i’ does not name a type 310 | for (int i = 1; i <= n; i++) { | ^ a.cpp:310:29: error: ‘i’ does not name a type 310 | for (int i = 1; i <= n; i++) { | ^ a.cpp:324:9: error: expected constructor, destructor, or type conversion before ‘(’ token 324 | free(cd); | ^ a.cpp:325:1: error: expected declaration before ‘}’ token 325 | } | ^ a.cpp:327:5: error: redefinition of ‘int main()’ 327 | int main() { | ^~~~ a.cpp:16:5: note: ‘int main()’ previously defined here 16 | int main() { | ^~~~ a.cpp: In function ‘int main()’: a.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ a.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d", &w[i]); | ~~~~~^~~~~~~~~~~~~根据这些报警作出修改
最新发布
11-18
正在启动生成... cmd /c chcp 65001>nul && D:/MinGW/bin/g++.exe -fdiagnostics-color=always -g C:\Users\34171\Desktop\code\.vscode\WJ\wj.c -o C:\Users\34171\Desktop\code\.vscode\WJ\wj.exe C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:1:27: error: expected constructor, destructor, or type conversion before '(' token 1 | printf("菜名: %s\n分类: %s\n食材: %s\n制作步骤: %s\n谁喜欢吃: %s\n", | ^ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:5:21: error: 'found' does not name a type 5 | found = 1; | ^~~~~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:6:17: error: expected declaration before '}' token 6 | } | ^ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:7:17: error: expected unqualified-id before 'break' 7 | break; | ^~~~~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:8:9: error: expected declaration before '}' token 8 | } | ^ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:9:5: error: expected declaration before '}' token 9 | } | ^ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:10:5: error: expected unqualified-id before 'if' 10 | if (!found) printf("未找到匹配结果。\n"); | ^~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:11:14: error: expected constructor, destructor, or type conversion before ';' token 11 | getchar(); | ^ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:12:1: error: expected declaration before '}' token 12 | } | ^ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c: In function 'void view_all_recipes()': C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:16:9: error: 'recipe_count' was not declared in this scope 16 | if (recipe_count == 0) { | ^~~~~~~~~~~~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:17:9: error: 'printf' was not declared in this scope 17 | printf("目前没有菜谱。\n"); | ^~~~~~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:1:1: note: 'printf' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'? +++ |+#include <cstdio> 1 | printf("菜名: %s\n分类: %s\n食材: %s\n制作步骤: %s\n谁喜欢吃: %s\n", C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:21:20: error: 'recipes' was not declared in this scope 21 | recipes[i].name, recipes[i].category, | ^~~~~~~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:20:13: error: 'printf' was not declared in this scope 20 | printf("菜名: %s\n分类: %s\n食材: %s\n制作步骤: %s\n谁喜欢吃: %s\n\n", | ^~~~~~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:20:13: note: 'printf' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'? C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:26:5: error: 'getchar' was not declared in this scope 26 | getchar(); | ^~~~~~~ C:\Users\34171\Desktop\code\.vscode\WJ\wj.c:26:5: note: 'getchar' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'? 生成已完成,但出现错误。 * 终端进程启动失败(退出代码: -1)。 * 终端将被任务重用,按任意键关闭。 * 正在执行任务: C/C++: g++.exe 生成活动文件 正在启动生成... cmd /c chcp 65001>nul && D:/MinGW/bin/g++.exe -fdiagnostics-color=always -g C:\Users\34171\Desktop\code\.vscode\WJ\wj.c -o C:\Users\34171\Desktop\code\.vscode\WJ\wj.exe D:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot open output file C:\Users\34171\Desktop\code\.vscode\WJ\wj.exe: Permission denied collect2.exe: error: ld returned 1 exit status 生成已完成,但出现错误。 * 终端进程已终止,退出代码: -1。 * 终端将被任务重用,按任意键关闭。
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值