通常関数とメンバー関数のやりとりでコンパイルエラー

このQ&Aのポイント
  • 通常関数とメンバー関数のやりとりでコンパイルエラーが発生しました。具体的には、`->SetValueXyzwpr2` の呼び出し部分でエラーが出ています。
  • `_DataPosReg` クラスは `COleDispatchDriver` を継承しており、`SetValueXyzwpr2` という関数を持っています。
  • `CFrrjiftestDlg` クラスの `pSysVarPos` メンバ変数の型 `_DataSysVarPos` は、クラス型へのポインタではないため、`SetValueXyzwpr2` の呼び出しがエラーになっています。
回答を見る
  • ベストアンサー

通常関数とメンバー関数のやりとりでコンパイルエラー

下記にあるようなプログラムをコンパイルしたら、下記のエラーになりました。 どこに問題があるのでしょうか? 「error C2227: '->SetValueXyzwpr2' : 左側がクラス、構造体、共用体、ジェネリック型へのポインタではありません。」 //frrjif.h class _DataPosReg : public COleDispatchDriver { // Operations public: BOOL SetValueXyzwpr2(long Index, float X, float Y, float Z, float W, float P, float R, float E1, float E2, float E3, short C1, short C2, short C3, short C4, short C5, short C6, short C7, short UF, short UT); }; //frrjiftestDlg.h #include "frrjif.h" class CFrrjiftestDlg : public CDialog { public: CFrrjiftestDlg(CWnd* pParent = NULL); // standard constructor virtual ~CFrrjiftestDlg(); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation _Core *pCore; _DataPosRegXyzwpr *pPosRegXyzwpr; _DataSysVarPos *pSysVarPos; }; //frrjiftestDlg.cpp #include "frrjiftestDlg.h" void MyDataHandler(sFrameOfData* FrameOfData) { CFrrjiftestDlg::pSysVarPos->SetValueXyzwpr2(X,Y,Z,W,P,R,E1,E2,E3,C1,C2,C3,C4,C5,C6,C7,UF,UT); //↑ここでコンパイルエラー //↑error C2227: '->SetValueXyzwpr2' : 左側がクラス、構造体、共用体、ジェネリック型へのポインタではありません。 } void CFrrjiftestDlg::OnBnClickedButton1() { Cortex_SetDataHandlerFunc(MyDataHandler); }

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

CFrrjiftestDlg::pSysVarPos->SetValueXyzwpr2(X,Y,Z,W,P,R,E1,E2,E3,C1,C2,C3,C4,C5,C6,C7,UF,UT); //↑ここでコンパイルエラー //↑error C2227: '->SetValueXyzwpr2' : 左側がクラス、構造体、共用体、ジェネリック型へのポインタではありません。 ええと、かなりキツい物言いですまないけども、 これがわからんなら基本ができてない。 メソッド呼ぶにはレシーバ(そのメソッドの持ち主:インスタンス)が必要。

ichigo61
質問者

補足

//.cpp void MyDataHandler(sFrameOfData* FrameOfData) { CFrrjiftestDlg obj; obj.sndrobot(); } void CFrrjiftestDlg::sndrobot() { pSysVarPos->SetValueXyzwpr2(X,Y,Z,W,P,R,E1,E2,E3,C1,C2,C3,C4,C5,C6,C7,UF,UT); } //.h class CFrrjiftestDlg : public CDialog { public: void sndrobot(); } この方法でコンパイルエラーは回避できました。

関連するQ&A

  • 左側がクラス、構造体、共用体、ジェネリック型への

    VS2008 でVC++のコンパイルをしたときに、 「error C2227: '->SetValueXyzwpr2' : 左側がクラス、構造体、共用体、ジェネリック型へのポインタではありません。」のエラーがでました。ネット上で、このエラーを探すと、GetValueXyzwprが定義していないとありますが、同じソース上の違う関数の中で使っているところではエラーがでません。今回新たに記述したところで発生しています。 【ソース】frrjiftestDlg.cpp void CFrrjiftestDlg::PrintFrameOfData(FILE *handle, sFrameOfData *FrameOfData)    pSysVarPos->SetValueXyzwpr2(X,Y,Z,W,P,R,E1,E2,E3,C1,C2,C3,C4,C5,C6,C7,UF,UT); ←ここでエラーがでます。 同じ、cpp 上で、 void CFrrjiftestDlg::OnButtonSetSysvar()  ←ここの中でも同じ使い方をしていますが、こちらではエラーはでません。 まったく、理由が分からず困り果てています。

  • [Visual C++ 6.0] コンパイル(ビルド)エラー

    ※参考までに『3週間完全マスターVisual C++ 6.0 』という本の「5日目」の部分を進めていて詰まってしまいました。 ビルドすると、下記のDialogsDlg.h中の「CMsgDlg m_dMsgDlg;」の辺りに対して error C2146: 構文エラー : ';' が、識別子 'm_dMsgDlg' の前に必要です。 error C2501: 'CMsgDlg' : 識別名を宣言するのに、型が指定されていません。 error C2501: 'm_dMsgDlg' : 識別名を宣言するのに、型が指定されていません。 というエラーが出てしまいます。CMsgDlgというクラスはちゃんと作っていますし、構文的にも間違ってはいないと思うのですが、何がいけないのでしょうか? 説明が足りなければ補足します(見づらくてスミマセン)。 // DialogsDlg.h : #if !defined(AFX_DIALOGSDLG_H__4772C7E5_F2C9_4E57_99B8_EF1D44426473__INCLUDED_) #define AFX_DIALOGSDLG_H__4772C7E5_F2C9_4E57_99B8_EF1D44426473__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif class CDialogsDlg : public CDialog { public: CDialogsDlg(CWnd* pParent = NULL); enum { IDD = IDD_DIALOGS_DIALOG }; CButton m_cWhichOption; CString m_sResults; protected: virtual void DoDataExchange(CDataExchange* pDX); protected: HICON m_hIcon; //{{AFX_MSG(CDialogsDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnExit(); afx_msg void OnYesnocancel(); afx_msg void OnAbortretryignore(); afx_msg void OnFileopen(); afx_msg void OnBcustomdialog(); afx_msg void OnBwhichoption(); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: CMsgDlg m_dMsgDlg; }; #endif

  • コンパイルすると error C1083 が出てしまいます

     -スペック- Microsoft Visual Studio 2008 Version 9.0.21022.8 RTM Microsoft .NET Framework Version 3.5 SP1 ---------------------------------------------------------------- 以下のプログラムを実行すると、error C1083: include ファイルを開けません。'myhelper.h': No such file or directory っていうエラーが出ます。 ----------------------------------------------------------------  -プログラム-  - mymain.cpp の中身 - #include "myhelper.h" #include "mymain.h" //自キャラのデータ Point2D g_jikipos = {40, 400}; //自キャラの座標 //画像ハンドル int g_jikiimage[11]; //色々なファイルの読み込み int LoadFiles(){ //画像ファイル読み込み if(LoadDivGraph("media\\player01.bmp", 11,11,1,64,64,g_jikiimage) == -1) return -1; return 1; }  - mymain.h の中身 - //他から呼び出させるMyMainの関数 void MyMain(); int LoadFiles();  - myhelper.h の中身 - #include "DxLib.h" #include <limits.h> #include <math.h> //構造体宣言 //座標またはベクトルを記録する構造体 struct Vector{ float x,y; }; typedef Vector Point2D; //線を記録する構造体 struct Line2D{ Point2D startpos, endpos; float katamuki; //傾きをラジアン値で記録 Vector speed; //移動している場合は速度をセット }; //球体を記録する構造体 struct Ball2D{ Point2D position; float hankei; //半径 }; //四角形を記録する構造体 struct Rect2D{ Point2D lefttop; Point2D rightbottom; float width; float height; }; //ライブラリ関数 Point2D PosInView(Point2D in); int XInView(float inx); int YInView(float iny); void ScrollToLeft(float jikiposx); void ScrollToRight(float jikiposx); void ScrollToUp(float jikiposy); void ScrollToDown(float jikiposy); void DrawLineInView(float x1, float y1, float x2, float y2, int Color, int Thickness); void DrawCircleInView(float x, float y, float r, int Color, int FillFlag); void DrawAnimation(float x, float y, double ExtRate, double Angle,int TurnFlag, int *imgarray, int allframe, float fps); //ベクトル関数 Vector CreateVector(Vector in, float veclen); Vector AddVector(Vector v1, Vector v2); Vector SubVector(Vector v1, Vector v2); Vector AddVectorInFrameTime(Vector pos, Vector speed); Vector AddVectorInFrameTime2(Vector pos, Vector speed, Vector accel); Vector Normalize(Vector in); Vector RotateVector(Vector in, float radian); float VectorLengthSquare(Vector in); float DotProduct(Vector v1, Vector v2); float CrossProduct(Vector v1, Vector v2); void SetLine2DKatamuki(Line2D *in); void DrawLine2D(Line2D in, int Color, int Thickness); void DrawBall2D(Ball2D in, int Color, int Fill); //当たり判定関数 bool HitTestLineAndBall(Line2D linein, Ball2D ballin); bool IsPointAtLineFace(Line2D linein, Point2D ptin); bool HitTestLineAndLine(Line2D line1, Line2D line2); bool HitTestBallAndBall(Ball2D a, Ball2D b); bool HitTestPointAndBox(Rect2D rect, Point2D pt); //タイマー関数 void SetSimpleTimer(int idx, int time); int GetPassedTime(int idx); //グローバル変数 extern float g_frametime; extern Rect2D g_framerect; //画面領域(当たり判定) extern Point2D g_current_field_pos; //現在の左上座標 extern Rect2D g_stagesize; //ステージサイズ //定数宣言 const float ZEROVALUE = 1e-10f; const float PIE = 3.1415926f; const int SCROLL_LIMIT = 200; myhelper.h はコピペなので間違ってはない。 ---------------------------------------------------------------- まだC言語初心者なので、どのようにすれば直せるのかわからないので 詳しくお願いします。 一応サイトで検索などをして、自分なりに調べてきて 定義が間違ってないかを見ましたけどそれでもまだわかりません。 それでは宜しくお願いします。

  • 関数ポインタにvirtual関数を与えたいです

    //関数ポインタについて質問させてください。 //error C2440: '=' : 'void (__thiscall A::* )(int,int)' から 'void (__cdecl *)(int,int)' に変換できません。 //というエラーが出ます。 //どうすればいいのか教えてください。 //よろしくお願いします。 #include<stdio.h> class A { public: void (*aaa)(int a,int b); virtual void test(int a,int b)=0; virtual void test2(int a,int b)=0; void execute() { aaa=test;//error C2440 } }; class B : public A { public: void test(int a,int b) { printf("test"); } void test2(int a,int b) { printf("test2"); } }; int main() { B b; b.execute(); b.aaa(2,3); return 0; }

  • bccでエラー:メンバー関数は呼び出すかそのアドレスを~

    クラスのメンバ関数を、ある関数(実は qsort)の引数として渡したい と思っています。環境は OS:Windows XP コンパイラ:C++Builder6 に付属の bcc32.exe です。 下記のコード(t.cpp)をコマンドプロンプトで bcc32 t としてコンパイルすると「※1」の行で下のエラーになります。 「エラー E2235 t.cpp 29: メンバー関数は呼び出すか  そのアドレスをとらなければならない(関数 main() )」 どのように直せば良いでしょうか? -------------------------------------------------------- #include <stdio.h> #include <stdlib.h> class Aclass { public: void f(int); }; void Aclass::f(int x) { printf("classfunc %d\n", x); } void sub1(int x) { printf("sub-1 %d\n", x); } void call_func(void(*func)(int), int x) { func(2*x + 1); } void main(void) { call_func((void(*)(int))sub1, 11); Aclass *a = new Aclass; call_func((void(*)(int))a->f, -7); //※1 delete a; } -------------------------------------------------------- この掲示板、行頭の空白が削除されてしまいますねー。

  • 静的でないメンバ関数の呼び出しが正しくありません

    コンパイル時に「静的でないメンバ関数の呼び出しが正しくありません」となってしまいます。 普通の関数からメンバー関数を呼び出すには、どう記述すればいいのでしょうか? void MyDataHandler(sFrameOfData* FrameOfData) { CFrrjiftestDlg::sndrobot();  ← ここがコンパイルエラー } void CFrrjiftestDlg::sndrobot() { いろいろ記述 } //*** 以下、ヘッダー class CFrrjiftestDlg : public CDialog { DECLARE_DYNAMIC(CFrrjiftestDlg); friend class CFrrjiftestDlgAutoProxy; // Construction public: CFrrjiftestDlg(CWnd* pParent = NULL); // standard constructor virtual ~CFrrjiftestDlg(); void msubInit(); void sndrobot();   ←ここで宣言 };

  • char型の変数をメンバーに含むクラス

    C++でchar型の変数をメンバーに含むクラスを作りました。 でも初期化の時に 「error C2065: 'Anna_Balyo' : 定義されていない識別子です」と怒られてしまいます。 それから一歩も進めません。 どこが悪いのか教えてください。お願いします。 class TimeOff { private: int idNum; enum { size = 20}; char empName[size]; //問題の変数定義; 雇用者の名前 float maxSickDays; float sickTaken; float maxVacation; float vacTaken; float maxUnpaid; float unpaidTaken; public: TimeOff() : idNum(0), empName(), maxSickDays(0.0), sickTaken(0.0), maxVacation(0.0), vacTaken(0.0), maxUnpaid(0.0), unpaidTaken(0.0) { } TimeOff(int iN, char eN[], float mS, float sT, float mV, float vT, float mU, float uT) : idNum(iN), empName(), maxSickDays(mS), sickTaken(sT), maxVacation(mV), vacTaken(vT), maxUnpaid(mU), unpaidTaken(uT) { } void showndays() const { cout << idNum << "\t" << empName << "\t" << maxSickDays << "\t" << sickTaken << "\t" << maxVacation << "\t" << vacTaken << "\t" << maxUnpaid << "\t" << unpaidTaken << endl; } }; int main() { TimeOff emp1(1000, Anna_Balyo, 200, 30, 20, 10, 40, 10); //エラー箇所 emp1.showndays(); return 0; }

  • メンバ関数(メソッド)をマルチスレッドにしたい

    環境はWinXPでVisual Studio 2005を使用しています。 C言語で関数をマルチスレッド化するにはこんな感じでOKでした。 // マルチスレッド関数 void Thread( void * ) { } void MainFunc() {   (HANDLE)_beginthread( Thread, 0, NULL ); } こんな風にスレッド関数をC++のメソッドに変えてうまくいくかと思い class Test_c { public:   void Thread( void * ); } ; // マルチスレッド関数 void Test_c::Thread( void * ) { } void MainFunc() {   Test_c t t;   (HANDLE)_beginthread( t.Thread, 0, NULL ); } とするとエラーが出てきてしまい、コンパイルが通りませんでした。 C++のメンバ関数をマルチスレッド関数としたい場合はどの様に書けばよいのでしょうか・・?

  • C++基底クラスに戻り値の異なる関数が宣言されている場合

    こんにちは。 質問させてください。 以下のようなコードがあったとします。 class Base1 { public:   virtual int get()=0; }; class Base2 { public:   virtual float get()=0; }; class Ex : public Base1, public Base2 { public:   int get(){return 0;}   float get(){return 0.0f;} }; void main() { } このプログラムをコンパイルすると 「'Ex::get': オーバーライドする仮想関数の戻り値の型が異なり、'Base1::get' の covariant ではありません。」 というエラーが出てしまいます。 関数の名前と引数が同じで戻り値だけが異なる場合はエラーが出るのはわかるのですが、基底クラスのBase1、Base2は変更不可能だとするとどのように回避すればいいのでしょうか? よろしくお願いします。 /*   WindowsXP Professional SP3   VisualStudio2005 AcademicEdition */

  • コンパイルエラー: LNK2001

    今、ベクトル計算を簡単にするクラスを作ってみようとしています。 //vector3.h template<class TT> class vector3{ public:   enum{NUM=3};   TT x[NUM];   void set(const TT *vv)void set(const TT *vv){     int i;     for(i=0;i<NUM;i++){       x[i]=vv[i];     }   } }; のように、set関数をクラスの中に書いていると問題無いのですが、以下のように、 //vector3.h template<class TT> class vector3{ public:   enum{NUM=3};   TT x[NUM];   void set(const TT *vv); }; //test.cpp #include"vector3.h" template<class TT> void vector3<TT>::set(const TT *vv){   int i;   for(i=0;i<NUM;i++){     x[i]=vv[i];   } } と、cppファイルの中に書き換えると以下のようにエラーが出るようになります。 error LNK2001: 外部シンボル ""public: void __thiscall vector3<double>::set(double const *)" (?set@?$vector3@N@@QAEXPBN@Z)" は未解決です。 fatal error LNK1120: 外部参照 1 が未解決です。 これはいったい何故なのでしょうか? 使用しているのはVisualC++2008ExpressEditionです 宜しくお願いします。

専門家に質問してみよう