0

i want to know how to access virtual table for a class this is my attempt to do so ........

#include<iostream>
using namespace std;
class sample
{
    public:
        virtual void  fun(int q)
        {
            cout<<"fun"<<endl;
            }
        
        void g()
        {
            int *p=(int *)this;
            p=(int *)*p;
            p=(int *)*p;
            void ( sample::*pfun)(int);
            pfun=(void(sample::*)(int))p;
           // pfun=(void (sample::*)(int))p;
            (*pfun)(25);
                
         }
         void abc()
       {
        cout<<"abc"<<endl;
        }
         
        
    };
    int main()
{
       sample s;
        s.g();
}

here i am getting error while casting the in the line
pfun=(void(sample::*)(int))p;

3
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by __avd
-1

the scope resolution operator have become smiley !!!!!

Votes + Comments
The scope operator would be the scope operator if you fsking learnt how to use CODE TAGS!!!!!!! 28 post, and you're still dumber than a box of rocks
0

If you haven't noticed, this is the C forum. You should post your question in the C++ forum. Perhaps it's better if you wait for a moderator to move your question for you to the right forum.

0

sorry for posting in the wrong place...
anyways i posted same thing on c++ forum so pls delete this thread from here

0

Function definition of g() should be:

void g(){
 int *p=(int *)this;
 typedef void (*pfun)(int);
 pfun p1=(pfun)*(int*)*(int*)p; // value of vptr.
 (p1)(25);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.