头文件:
#ifndef TRY_H
#define TRY_H
namespace Foam
{
class Istream
{
public:
double he;
Istream(double t)
{he=t;}
};
class intd
{
public:
double b;
intd(const Istream & Is)
{b=Is.he;}
};
}
#endif // TRY_H
源文件
#include <iostream>
#include "try.H"
using namespace std;
int main()
{
Foam::intd sb(Foam::Istream(1));
cout<<sb.b<<endl;
return 0;
}
要点:1. 构造函数的参数声明必须有const限定。
2. 无名对象必须由常量构造产生。(无名对象构造函数有多个参数时也可以由变量产生)