标题:新手请教各位高手一个C++问题!急!!
只看楼主
APFNTCHUO
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-4-20
 问题点数:0 回复次数:0 
新手请教各位高手一个C++问题!急!!
本人在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
搜索更多相关主题的帖子: Phone Linux 
2008-04-20 11:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-210018-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.988536 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved