设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 1663|回复: 0
打印 上一主题 下一主题

新手请教各位高手一个C++问题!急!!

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-4 00:23:25 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
本人在Linux下编译C++程序时,其中一个文件发生错误:系统提示,在文件的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: thomas.germer@nist.gov
//**
//** 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 TYPE>
class Vector3D_Base {
    public:
        //
        // The components of the vector:
        //
        TYPE x,y,z;

        // Class constructors:
        Vector3D_Base<TYPE>() {}
        Vector3D_Base<TYPE>(const TYPE& a,const TYPE& b,const TYPE& c)
                            {x=a;y=b;z=c;}      
        
        // Class destructor:
        virtual ~Vector3D_Base<TYPE>() {}

        // Non-converting copy constructor:
        Vector3D_Base<TYPE>(const Vector3D_Base<TYPE>& a)
            : x(a.x),y(a.y),z(a.z) {}     

        // Assignment operator:
        Vector3D_Base<TYPE>& operator=(const Vector3D_Base<TYPE>& a)
                { x=a.x; y=a.y; z=a.z; return *this; }   
        
        // Addition of vectors:
        Vector3D_Base<TYPE> operator+(const Vector3D_Base<TYPE>& a) const
                { return Vector3D_Base<TYPE>(x+a.x,y+a.y,z+a.z); }
        
        // Subtraction of vectors:
        Vector3D_Base<TYPE> operator-(const Vector3D_Base<TYPE>& a) const
                { return Vector3D_Base<TYPE>(x-a.x,y-a.y,z-a.z); }
        
        // Unary minus sign:
        Vector3D_Base<TYPE> operator-() const
                { return Vector3D_Base<TYPE>(-x,-y,-z); }
        
        // Scalar product of two vectors:
        TYPE operator*(const Vector3D_Base<TYPE>& a) const
                { return x*a.x+y*a.y+z*a.z; }
        
        // Product of vector with scalar:
        Vector3D_Base<TYPE> operator*(const TYPE& b) const
                { return Vector3D_Base<TYPE>(x*b,y*b,z*b); }
        friend Vector3D_Base<TYPE> operator*(const TYPE& b,
                                             const Vector3D_Base<TYPE>& a)
                {return Vector3D_Base<TYPE>(a.x*b,a.y*b,a.z*b); }
        
        // Division of a vector by a scalar:
        Vector3D_Base<TYPE> operator/(const TYPE& a) const
                { return Vector3D_Base<TYPE>(x/a,y/a,z/a); }
        
        // The cross product of two vectors:
        friend Vector3D_Base<TYPE> cross(const Vector3D_Base<TYPE>& a,
                                         const Vector3D_Base<TYPE>& b)
                { return Vector3D_Base<TYPE>(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 <class TYPE2>
        void copy(const Vector3D_Base<TYPE2>& a)
            { x=a.x; y=a.y; z=a.z; }

};

//
// Define templated Vector3D
//
template <class TYPE> class Vector3D: public Vector3D_Base<TYPE> {};

//
// Define Vector3D<double>
//
template <>
class Vector3D<double> : public Vector3D_Base<double> {
public:
    // Constructors:
    Vector3D<double>() {};
    Vector3D<double>(const Vector3D<double>& a)
        : Vector3D_Base<double>(a) {}
    Vector3D<double>(const Vector3D_Base<double>& a)
        : Vector3D_Base<double>(a) {}
    Vector3D<double>(double ax,double ay,double az)
        :  Vector3D_Base<double>(ax,ay,az) {}
   
    // The norm of a vector:
    friend double Norm(const Vector3D_Base<double>& a)
        { return sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }

    // A vector of unit length:
    friend Vector3D<double> unit(const Vector3D_Base<double>& a)
                { return a/Norm(a); }

    // A function returning a vector having specific polar coordinates:
    friend Vector3D_Base<double> polar(double r,double theta,double phi) {
            return Vector3D_Base<double>(r*sin(theta)*cos(phi),
                                  r*sin(theta)*sin(phi),
                                  r*cos(theta));
    }
};

//
// Defining Vector3D<COMPLEX>
//
template <>
class Vector3D<COMPLEX > : public Vector3D_Base<COMPLEX > {
public:
    // Constructors:
    Vector3D<COMPLEX >() {};
    Vector3D<COMPLEX >(const Vector3D<COMPLEX >& a)
        : Vector3D_Base<COMPLEX >(a)  {}
    Vector3D<COMPLEX >(const Vector3D_Base<COMPLEX >& a)  
        : Vector3D_Base<COMPLEX >(a)  {}
    Vector3D<COMPLEX >(const COMPLEX & ax,
                       const COMPLEX & ay,
                       const COMPLEX & az)
                       :  Vector3D_Base<COMPLEX >(ax,ay,az) {}

    // Constructor which converts from a real vector to a complex vector:
    Vector3D<COMPLEX >(const Vector3D_Base<double>& a) { copy(a); }

    // The norm of a complex vector:
    friend COMPLEX Norm(const Vector3D_Base<COMPLEX >& a)
                { return std::sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }

    // A vector of unit length:
    friend Vector3D<COMPLEX > unit(const Vector3D_Base<COMPLEX >& a)
                { return a/Norm(a); }

};

// A vector perpendicular to two vectors:
Vector3D<double> perpto(const Vector3D<double>& a,
                        const Vector3D<double>& b);
Vector3D<COMPLEX > perpto(const Vector3D<COMPLEX >& a,
                          const Vector3D<COMPLEX >& b);               

// Some useful typedefs for the SCATMECH library:
typedef Vector3D<double> Vector;
typedef Vector3D<COMPLEX > CVector;

#ifndef NO_SCATMECH_NAMESPACE
} // namespace SCATMECH
#endif // NO_SCATMECH_NAMESPACE

#endif // VECTOR3D_H
您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-19 00:41 , Processed in 0.072973 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表