|
下面文件有KenoComm.h ,KenoComm.c ,b.c三个文件,还有Makefile文件.
类CKenoComm定义在KenoComm.c中,b.c调用了类CKenoComm.
我在linux下编译时,问题是
[root@localhost 7.12]# make
cc -c -o b.o b.c
In file included from b.c:5:
KenoComm.h:14: parse error before "CKenoComm"
KenoComm.h:15: syntax error before '{' token
KenoComm.h:19: warning: data definition has no type or storage class
KenoComm.h:20: parse error before '~' token
b.c: In function `main':
b.c:9: parse error before "a"
b.c:10: `a' undeclared (first use in this function)
b.c:10: (Each undeclared identifier is reported only once
b.c:10: for each function it appears in.)
make: *** [b.o] Error 1
那位大侠能帮我解决一下吗,先谢谢了.
我的新建类的头文件是KenoComm.h
// KenoComm.h: interface for the CKenoComm class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_KENOCOMM_H__3781E982_B927_4046_B209_1D8827A17071__INCLUDED_)
#define AFX_KENOCOMM_H__3781E982_B927_4046_B209_1D8827A17071__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stdio.h>
class CKenoComm
{
public:
void DelPipe();
int ReadPipe();
CKenoComm();
virtual ~CKenoComm();
};
#endif // !defined(AFX_KENOCOMM_H__3781E982_B927_4046_B209_1D8827A17071__INCLUDED_)
我的新建类的.cpp文件为KenoComm.c
// KenoComm.c: implementation of the CKenoComm class.
//
//////////////////////////////////////////////////////////////////////
//#include "stdafx.h"
#include "KenoComm.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CKenoComm::CKenoComm()
{
}
CKenoComm::~CKenoComm()
{
}
int CKenoComm::ReadPipe()
{
printf("ReadPipe\n");
return 1;
}
void CKenoComm::DelPipe()
{
printf("DelPipe\n");
}
我的主文件为 b.c
#include "KenoComm.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
CKenoComm a;
a.DelPipe();
a.ReadPipe();
printf("Hello World!\n");
return 0;
}
我的Makefile文件为
RM = rm -f
CXX = g++
#CXXFLAGS = +DA2.0W -s
CXXFLAGS = +O3
Pipe: PipeComm
OBJS_PipeComm = b.o KenoComm.o
PipeComm : $(OBJS_PipeComm)
$(RM)$@
$(CXX) -o $@ $(CXXLDFLAGS) $(OBJS_PipeComm)
clean:
$(RM) core PipeComm* *.o |
|