谁能在linux下用gcc编译通过这段程序?(高手请进)

qrwulysses 2002-07-22 02:21:14
程序本身没有意义,可是在solaris下和window下都可以编译通过,在linux下却通不过,怀疑是c++的标准不同,谁可以不改程序直接在gcc中加选项编译通过?
(实在不行用最小量改程序)


#include <iostream.h>
#define SDEFINE sample i;\
i.print();
template<class TYPE>
void DestructElements(TYPE* pElements, int nCount)
{
if(!(nCount == 0 )) {
SDEFINE;
}

// call the destructor(s)
for (; nCount--; pElements++)
pElements->~TYPE();
}

class sample
{
private:
int a,b;
public:
friend class sample;
friend void sum(sample& obj);
void print();
};
void sample::print()
{
cout<<"ok"<<endl;
}
void sum(sample& obj)
{
obj.a=2;
obj.b=3;
cout<<obj.a<<endl;
}
int main()
{
sample i;
sample& j = i;
sum(j);
return 0;
}
...全文
52 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
glassshark 2002-07-22
  • 打赏
  • 举报
回复
使用g++编译。g++ -o main *.cpp;./main
#include <iostream.h>
#define SDEFINE sample i;\
i.print();
template<class TYPE>
void DestructElements(TYPE* pElements, int nCount)
{
if(!(nCount == 0 )) {
SDEFINE
}

// call the destructor(s)
for (; nCount--; pElements++)
pElements->~TYPE();
}

class sample
{
private:
int a,b;
public:
friend class sample;
friend void sum(sample& obj);
void print();
};
void sample::print()
{
cout<<"ok"<<endl;
}
void sum(sample& obj)
{
obj.a=2;
obj.b=3;
cout<<obj.a<<endl;
}
int main()
{
sample i;
sample& j = i;
sum(j);
return 0;
}

19,614

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧