【发布时间】:2014-07-10 12:28:55
【问题描述】:
我正在尝试交叉编译一些代码,但我有这行给出错误,我不知道它应该做什么,所以我可以修复它。
typedef std::complex
复杂* _matrix[MATRIX_NODES+OFFSET]; // 对于 tran,real 现在是,imag 被保存。
_matrix[ii][jj].real() = 0;
我不确定 =0 应该做什么。它用 clang 和 g++ 编译,但不是 emscripten。 emscripten 有一个不同的复数库。 有谁知道如何解决这个问题?
这里是emscripten中的定义,与常规库不同。
template<>
class _LIBCPP_TYPE_VIS_ONLY complex<double>
{
double __re_;
double __im_;
public:
typedef double value_type;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0)
: __re_(__re), __im_(__im) {}
_LIBCPP_CONSTEXPR complex(const complex<float>& __c);
explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double imag() const {return __im_;}
_LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
_LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
_LIBCPP_INLINE_VISIBILITY complex& operator= (double __re)
{__re_ = __re; __im_ = value_type(); return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator+=(double __re) {__re_ += __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator-=(double __re) {__re_ -= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator*=(double __re) {__re_ *= __re; __im_ *= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator/=(double __re) {__re_ /= __re; __im_ /= __re; return *this;}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
{
__re_ = __c.real();
__im_ = __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
{
__re_ += __c.real();
__im_ += __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
{
__re_ -= __c.real();
__im_ -= __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
*this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
*this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
我写了这个简短的例子
#include <iostream>
#include <complex>
using namespace std;
int main(int argc, const char *argv[]){
complex<double> x;
x.real(1);
cout<<x.real()<<'\n';
x.real()=0;
cout<<x.real()<<'\n';
x.real(2);
cout<<x.real()<<'\n';
double* y=&x.real();
cout<<*y<<'\n';
}
它使用 -std=c++98 而不是 -std=c++11 编译。 我在 emscripten 上尝试了 -std=c++98 但它似乎没有做任何事情。
有什么想法吗?
【问题讨论】:
-
= 0正是它的样子——赋值为 0。我假设real()方法返回对复数实部的引用;赋值将其设置为 0。你说它不能用 emscripten 编译,但你甚至没有说你得到什么错误消息...... -
抱歉,错误:表达式不可赋值
-
可能是编译器设置?
标签: c++ emscripten