免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3815 | 回复: 5
打印 上一主题 下一主题

[C++] 求助关于C++类之间相互调用的问题。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-10 14:21 |只看该作者 |倒序浏览
我用C++写了两个类,两个类的源文件在同一个目录下。我想在其中一个类中调用另一个。下面是调用类的头文件源码

#ifndef NET_TRANSMITTER_H
#define NET_TRANSMITTER_H

#include "configfile.h"

const static int MAX_RECV_SIZE = 1024 * 5;

class NetTransmitter
{
        public:
                NetTransmitter();
                NetTransmitter(ConfigFile* conf);
                virtual ~NetTransmitter();

                //set and get configuration file
                void setConfigFile(ConfigFile* conf);
                const ConfigFile* getConfigFile(void);

                // set and get wait for response flag
                void setWaitFlag(bool flag);
                bool getWaitFlag(void);
          。。。。。。。。。。。。。
          。。。。。。。。。。。。。
          。。。。。。。。。。。。。
};


我用下面的语句编译这个类的cpp文件。结果如下。

root@sun1 # g++ -c -lsocket -lnsl nettrans.cpp
In file included from nettrans.cpp:10:
nettrans.h:11: error: parse error before `*' token
nettrans.h:14: error: syntax error before `&&' token
nettrans.h:16: error: ISO C++ forbids declaration of `ConfigFile' with no type
nettrans.h:16: error: parse error before `*' token
nettrans.h:44: error: syntax error before `*' token
In file included from nettrans.cpp:10:
nettrans.h:52:24: warning: no newline at end of file
。。。。。。。。。。。。
。。。。。。。。。。。。。。

结果好像系统不认类的调用,我不知道该怎么解决,求助各位大侠指点一二!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2004-06-10 18:15 |只看该作者

求助关于C++类之间相互调用的问题。

你把"configfile.h"的路径在编译命令中加入试试。

论坛徽章:
0
3 [报告]
发表于 2004-06-10 20:20 |只看该作者

求助关于C++类之间相互调用的问题。

g++ -c  -l./ -lsocket -lnsl nettrans.cpp
是这样吗?

论坛徽章:
0
4 [报告]
发表于 2004-06-11 10:20 |只看该作者

求助关于C++类之间相互调用的问题。

应该是把两个文件分别编译成*.o文件再进行链接吧?

论坛徽章:
0
5 [报告]
发表于 2004-06-11 11:24 |只看该作者

求助关于C++类之间相互调用的问题。

编译通过勒,多谢各位高手!

论坛徽章:
0
6 [报告]
发表于 2004-06-11 11:24 |只看该作者

求助关于C++类之间相互调用的问题。

编译通过了,多谢各位大侠的指点
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP