コンソールアプリです。 Vector();関数部でコンストラクタのコードコメント部ですが**ソースファイルとヘッダーファイルを分ける際にどうすれば関数ポインタを実装できるのでしょうか?**コンストラクタの時点でそのメンバポインタ変数に関数ポインタを入れておきたいのですが?
エラーコード[ 型 "void (Vector::)()" の値を型 "void ()()" のエンティティに割り当てることはできません ]
開発環境: visual studio 2019
OS: Windows 10
int main() { Vector v; }
Vector.hpp
#ifndef ___Vector_H #define ___Vector_H class Vector { //private: public: float x; float y; float z; Vector(float xx, float yy, float zz); Vector(); static Vector cross(Vector a, Vector b);//外積 static float dot(Vector a, Vector b);//内積 static Vector mul_scalar(float a, Vector v);//スカラーとベクトルの掛け算 /******/ void (*func_ptr)(); void func(); /******/ Vector operator = (Vector v); Vector operator + (Vector v); Vector operator - (Vector v); }; class Quaternion { public: /*実部*/ float a; /*虚部*/ // Vector<type> v; Vector v; Quaternion(float aa, Vector vv); Quaternion(); Quaternion operator * (Quaternion t); }; #endif
Vector.cpp
#include "Vector.hpp" #include "stdio.h" /*ベクトル x スカラーの掛け算*/ Vector Vector::mul_scalar(float a, Vector v) { return Vector(a * v.x, a * v.y, a * v.z); } /*外積 ベクトル x ベクトル*/ Vector Vector::cross(Vector a, Vector b) { return Vector((a.y * b.z) - (a.z * b.y), (a.z * b.x) - (a.x * b.z), (a.x * b.y) - (a.y * b.x)); } Vector Vector::operator - (Vector v) { return Vector((x - v.x), (y - v.y), (z - v.z)); } /*内積*/ float Vector::dot(Vector a, Vector b) { return (a.x * b.x) + (a.y * b.y) + (a.z * b.z); } /*コンストラクタ*/ Vector::Vector(float xx, float yy, float zz) { x = xx; y = yy; z = zz; } ////////////////////////////////////////////////// /*コンストラクタ*/ Vector::Vector() { func_ptr = func; x = 0.0f; y = 0.0f; z = 0.0f; } //////////////////////////////////////////////// /*オペレーター = */ Vector Vector::operator = (Vector v) { this->x = v.x; this->y = v.y; this->z = v.z; return *this; } /*オペレーター + */ Vector Vector::operator + (Vector v) { Vector t; t.x = this->x + v.x; t.y = this->y + v.y; t.z = this->z + v.z; return t; } /*コンストラクタ 実部、虚部(Vector) */ Quaternion::Quaternion(float aa, Vector vv) { a = aa;//実部 /*虚部*/ v = vv; } /*コンストラクタ 引数なし*/ Quaternion::Quaternion() { a = 0.0f;//実部 /*虚部*/ v.x = 0.0f; v.y = 0.0f; v.z = 0.0f; } /*クォータニオン同士の掛け算 A = (a; U) B = (b; V) AB = (ab - U・V; aV + bU + U×V) */ Quaternion Quaternion::operator * (Quaternion t) { return Quaternion(this->a * t.a - Vector::dot(this->v, t.v), Vector(Vector::mul_scalar(this->a, t.v) + Vector::mul_scalar(t.a, this->v) + Vector::cross(this->v, t.v))); } //////////////////////////////// void Vector::func() { printf("関数ポインタ\n"); } /////////////////////////////////
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/04/22 09:07 編集
2020/04/22 09:38
退会済みユーザー
2020/04/22 11:08
2020/04/22 13:50