红联Linux门户
Linux帮助

向各位高手请教问题!

发布时间:2008-04-20 01:09:25来源:红联作者:APFNTCHUO
编辑下面程序时,系统提示我第121和157行的Norm函数在作用域内未声明,这是一个很大的程序,我只能提供这个头文件!请大家帮忙!!
//******************************************************************************
//** SCATMECH: Polarized Light Scattering C++ Class Library
//**
//** File: vector3d.h
//**
//** Thomas A. Germer
//** Optical Technology Division, National Institute of Standards and Technology
//** 100 Bureau Dr. Stop 8442; Gaithersburg, MD 20899-8442
//** Phone: (301) 975-2876; FAX: (301) 840-8551
//** Email: [email=thomas.germer@nist.gov]thomas.germer@nist.gov[/email]
//**
//** Version: 3.01 (May 2002)
//**
//******************************************************************************
#ifndef SCATMECH_VECTOR3D_H
#define SCATMECH_VECTOR3D_H
#include "scatmech.h"
#ifndef NO_SCATMECH_NAMESPACE
namespace SCATMECH {
#endif // NO_SCATMECH_NAMESPACE
//
// template class Vector3D_Base is used by the class Vector3D
//
template
class Vector3D_Base {
public:
//
// The components of the vector:
//
TYPE x,y,z;
// Class constructors:
Vector3D_Base() {}
Vector3D_Base(const TYPE& a,const TYPE& b,const TYPE& c)
{x=a;y=b;z=c;}

// Class destructor:
virtual ~Vector3D_Base() {}
// Non-converting copy constructor:
Vector3D_Base(const Vector3D_Base& a)
: x(a.x),y(a.y),z(a.z) {}
// Assignment operator:
Vector3D_Base& operator=(const Vector3D_Base& a)
{ x=a.x; y=a.y; z=a.z; return *this; }

// Addition of vectors:
Vector3D_Base operator+(const Vector3D_Base& a) const
{ return Vector3D_Base(x+a.x,y+a.y,z+a.z); }

// Subtraction of vectors:
Vector3D_Base operator-(const Vector3D_Base& a) const
{ return Vector3D_Base(x-a.x,y-a.y,z-a.z); }

// Unary minus sign:
Vector3D_Base operator-() const
{ return Vector3D_Base(-x,-y,-z); }

// Scalar product of two vectors:
TYPE operator*(const Vector3D_Base& a) const
{ return x*a.x+y*a.y+z*a.z; }

// Product of vector with scalar:
Vector3D_Base operator*(const TYPE& b) const
{ return Vector3D_Base(x*b,y*b,z*b); }
friend Vector3D_Base operator*(const TYPE& b,
const Vector3D_Base& a)
{return Vector3D_Base(a.x*b,a.y*b,a.z*b); }

// Division of a vector by a scalar:
Vector3D_Base operator/(const TYPE& a) const
{ return Vector3D_Base(x/a,y/a,z/a); }

// The cross product of two vectors:
friend Vector3D_Base cross(const Vector3D_Base& a,
const Vector3D_Base& b)
{ return Vector3D_Base(a.y*b.z-a.z*b.y,
a.z*b.x-a.x*b.z,
a.x*b.y-a.y*b.x); }

protected:

// A type-converting copy function:
template
void copy(const Vector3D_Base& a)
{ x=a.x; y=a.y; z=a.z; }
};
//
// Define templated Vector3D
//
template class Vector3D: public Vector3D_Base {};
//
// Define Vector3D
//
template <>
class Vector3D : public Vector3D_Base {
public:
// Constructors:
Vector3D() {};
Vector3D(const Vector3D& a)
: Vector3D_Base(a) {}
Vector3D(const Vector3D_Base& a)
: Vector3D_Base(a) {}
Vector3D(double ax,double ay,double az)
: Vector3D_Base(ax,ay,az) {}

// The norm of a vector:
friend double Norm(const Vector3D_Base& a)
{ return sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }
// A vector of unit length:
friend Vector3D unit(const Vector3D_Base& a)
{ return a/Norm(a); }
// A function returning a vector having specific polar coordinates:
friend Vector3D_Base polar(double r,double theta,double phi) {
return Vector3D_Base(r*sin(theta)*cos(phi),
r*sin(theta)*sin(phi),
r*cos(theta));
}
};
//
// Defining Vector3D
//
template <>
class Vector3D : public Vector3D_Base {
public:
// Constructors:
Vector3D() {};
Vector3D(const Vector3D& a)
: Vector3D_Base(a) {}
Vector3D(const Vector3D_Base& a)
: Vector3D_Base(a) {}
Vector3D(const COMPLEX & ax,
const COMPLEX & ay,
const COMPLEX & az)
: Vector3D_Base(ax,ay,az) {}
// Constructor which converts from a real vector to a complex vector:
Vector3D(const Vector3D_Base& a) { copy(a); }
// The norm of a complex vector:
friend COMPLEX Norm(const Vector3D_Base& a)
{ return std::sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }
// A vector of unit length:
friend Vector3D unit(const Vector3D_Base& a)
{ return a/Norm(a); }
};
// A vector perpendicular to two vectors:
Vector3D perpto(const Vector3D& a,
const Vector3D& b);
Vector3D perpto(const Vector3D& a,
const Vector3D& b);
// Some useful typedefs for the SCATMECH library:
typedef Vector3D Vector;
typedef Vector3D CVector;
#ifndef NO_SCATMECH_NAMESPACE
} // namespace SCATMECH
#endif // NO_SCATMECH_NAMESPACE
#endif // VECTOR3D_H

[ 本帖最后由 APFNTCHUO 于 2008-4-20 09:18 编辑 ]
文章评论

共有 1 条评论

  1. gongji110 于 2008-04-20 10:18:11发表:

    你搜一下Norm函数在哪个库了,或者编译的时候要添加哪个库,就可以解决了。