Iオブジェクトは、それが法的な初期化子リストに一時的に返す関数を使用することです
Segment::Segment(QPointF const& start, QPointF const& end):
mOrigin(toVector3df(start)),mEnd(toVector3df(end)){
}
mOrigin
の次のコンストラクタは、種類Vector3df
と一時Vector3df
返すtoVector3df(QPointF const&)
機能である持っています。ここまでは順調ですね。コードはうまくコンパイルされ、linux、gcc 4.4.3の魅力のように動作します。ほとんどの警告が有効になります。
include/vector3d.h: In constructor 'Segment::Segment(const QPointF&, const QPointF&)':
include/vector3d.h:64: warning: 'this.902' is used uninitialized in this function
include/vector3d.h:64: note: 'this.902' was declared here
は、まず::もちろん本当ありません
は、今私がしたかった私は非常に奇妙なコンパイラの警告を取得するノキアのスマートフォン(Meamoフリーマントル) と突然のすべてのために同じコードをクロスコンパイル変数はthis.902という名前の 'Vecto3df'の中にあります。私の最初の質問は次のようなものです。さらにVector3df
コンストラクタには何も問題はありません。それらは非常に単純で、コードの他の部分でも完璧に動作する1つの非メンバーテンプレート関数です。 Vector3df
は、メンバではない関数を定義するテンプレートから継承し、変数はありません。仮想関数はありません。
第二に、私は次のよう
Segment::Segment(QPointF const& start, QPointF const& end):
mOrigin(),mEnd(){
mOrigin = toVector3df(start);
mEnd = toVector3df(end);
}
に上記のコードを変更すると、コードは警告なしで正常に動作します。 ここで私は何が欠けていますか?誰もが警告の起源が何であるかという考えを持っています。私が気付いていない教義に違反していますか? fremantleコンパイラ(Maemo 5、Qt 4.6.2)はより重大であるかバグですか?事前に
おかげで、マーティン
編集:ここでは は最小限の例では、長さのため申し訳ありません:-P
#include <iostream>
#include <sstream>
#include <QPoint>
template<typename T> class IoEnabled {};
template<typename T>
class Vector3d: public IoEnabled<Vector3d<T> > {
private:
T mX; T mY; T mZ;
public:
Vector3d(T const& x, T const& y, T const& z=0.0) : mX(x), mY(y), mZ(z) {}
};
typedef Vector3d<float> Vector3df;
template<class T>
Vector3df toVector3df(T const& p){
return Vector3df(p.x(),p.y(),0.0);
}
class Segment {
private:
Vector3df mOrigin; Vector3df mEnd;
public:
Segment(QPointF const& start, QPointF const& end):
mOrigin(toVector3df(start)),mEnd(toVector3df(end)){
//if toVector3df(...) is moved from the initializer to the body it works
}
};
int main(int argc, char **argv) {
(void) argc; (void) argv;
Segment temp(QPointF(1,2),QPointF(3,4));
return 0;
}
コンパイラの呼び出し:
g++ -c -pipe -Werror -Wall -Wextra -Wunused -Wundef -Wpointer-arith -Wcast-align -Wwrite-strings -Wredundant-decls -O3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -D_REENTRANT -Wall -W -DQT_GL_NO_SCISSOR_TEST -DQT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH=1024 -DMAEMO -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/opt/QtSDK/Maemo/4.6.2/sysroots/fremantle-arm-sysroot-20.2010.36-2-slim/usr/share/qt4/mkspecs/linux-g++-maemo5 -I. -I/opt/QtSDK/Maemo/4.6.2/sysroots/fremantle-arm-sysroot-20.2010.36-2-slim/usr/include/QtCore -I/opt/QtSDK/Maemo/4.6.2/sysroots/fremantle-arm-sysroot-20.2010.36-2-slim/usr/include/QtGui -I/opt/QtSDK/Maemo/4.6.2/sysroots/fremantle-arm-sysroot-20.2010.36-2-slim/usr/include -Isrc -Irelease/moc -o release/obj/main.o src/main.cpp
テンプレートの継承は思わVector3dがすべて継承しない場合は重要です。
'toVector3df'はメンバ関数ですか? –
メンバー以外のテンプレートはありません – Martin
これを小さな例で再現できますか?質問に貼り付けることはできますか? –