菜鸟问题,函数可以编译生成DLL,类咋就不成呢?
czb 2007-04-14 09:57:56 /* 文件名:lib.h */
#include <string>
#ifndef LIB_H
#define LIB_H
int add(int x,int y);
int sub(int x,int y);
//class CPerson{
//public:
// int id;
// string name;
//public:
// void setID(int id);
// void setName(string name);
// void printID();
// void printName();
//};
#endif
#include "stdafx.h"
#include "lib.h"
int add(int x, int y)
{
return x + y;
}
int sub(int x,int y)
{
return x-y;
}
//void CPerson::setID(int id)
//{
// this.id = id;
//}
//
//void CPerson::setName(string name);
//{
// this.name = name;
//}
//
//void CPerson::printID(string name);
//{
// cout << id << endl;
//}
//
//void CPerson::printName(string name);
//{
// cout << name << endl;
//}
如上面的文件内容,单单编译add、sub函数是可以编译成DLL的,不过如果把类的注释去掉,就死都编译不过了,报错"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int"。即使把add、sub函数的声明和实现去掉,仅留下类CPerson,也编译不过。
编译器是vs2005
我现在是函数和类都要保留,因为类不能导出给其它语言调用,所以就转了个弯,先弄个函数,在函数里调用类。如果哪位大虾除了COM之外还有其它的方法,也请指出。