testクラス部の以下コード部ですがコメント部のusingを使わない宣言方法ではエラーにならないのですが
なぜusingを使うとエラーになるのでしょうか? &を使ってくださいとのエラーが出るのですが&をつけたりその他思い当たるコード編集を行いましたがエラーが取れません自分の勘では”そもそもできない”(コメント部はエラーにならないので)のではと思うのでですがその辺はどうなのでしょうか?原因を教えてくれますでしょうか?
//void(test::*t)() = &test::print; tp *t = &test::print;//1
#include <iostream> #include "conio.h" using namespace std; using tp = void(*)(); class v { }; class test { int a; public: test():a(0){ } void print() { cout << a << endl; } //void(test::*t)() = &test::print; tp *t = &test::print;//1 void f2(int x) { a = x; } virtual void vf() { cout << "仮想関数\n"; } void ft() { cout << "test()\n"; } // virtual void vf2() = 0;//純枠仮想関数 protected: void pf() { cout << "protected\n"; } }; class sample : public test { int a; public: void fx() { pf(); } void fs() { cout << "sample()\n"; } sample():a(0) { } void vf() { cout << "派生関数\n"; } void print() { cout << a<<endl; } void f2(int x) { a = x; } virtual void vf2() { cout << "純枠仮想関数\n"; } }; void f3() { } int main() { test *sa = new test(); sa->vf(); //sa->vf2(); sa->f2(3); sa->print(); delete sa; sa = new sample(); sa->ft(); sa->print(); sa->f2(7); test* sb = (test*)sa; sb = (sample*)sb; //tp t = f3; //tp t = sa->print;//2 sb->print(); //sb->vf(); // sb->vf2(); int _r = _getch(); return 0; }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。