64,654
社区成员
发帖
与我相关
我的任务
分享
//
// foo.h
//
#ifndef FOO_H
#define FOO_H
#ifdef FOO_EXPORTS
#define FOO_API __declspec(dllexport)
#else
#define FOO_API __declspec(dllimport)
#endif
class FOO_API Foo {
public:
Foo();
int get_id(void);
void set_id(int id);
private:
int m_id;
};
#endif // FOO_H
//
// foo.cpp
//
#define FOO_EXPORTS
#include "foo.h"
Foo::Foo()
{
m_id = 0;
}
int Foo::get_id(void)
{
return m_id;
}
void Foo::set_id(int id)
{
m_id = id;
}
//
// main.cpp
//
#include <stdio.h>
#include "foo.h"
int
main(void)
{
Foo foo;
printf("%d\n", foo.get_id());
foo.set_id(10);
printf("%d\n", foo.get_id());
return 0;
}
class SampleClass
{
public:
SampleClass& GetSampleClass()
{
return *this;
}
/*.........
* other members of the class
*/
};
class Sample
{
//...........
};
class GetClass
{
public:
//下面仅提供了默认构造函数和析构函数,强烈建议自行添加拷贝构造函数和重载赋值函数
GetClass()
:sample(new Sample) //调用Sample类的构造函数,如果是调用有参构造函数,代码自行添加
{
}
~GetClass()
{
delete sample;
}
public:
//const Sample* GetSampleClass() const
//{
// return sample;
//}
Sample* GetSampleClass()
{
return sample;
}
private:
Sample* sample;
};