CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Virtual Functions and pointers topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2008, 05:21 AM
Junior Member
 
Join Date: Jun 2008
Location: Milano, Italy
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Spogliani is on a distinguished road
| More
Virtual Functions and pointers

Hi to everyone

I'm writing this post because I have some problems accessing a function of a class through a pointer.

This is the situation:
I have a pointer to a class. The class inherits two virtual functions from an abstract base class.

The problem is the following:
When I try to call the function from the pointer I receive the following error at run-time: "Unhandled exception at 0x004251d8 in MyApplication.exe: 0xC0000005: Access violation reading location 0x00000000."

Can somebody help me, please?

here the declaration of the pointer and the functions:
Code:
//baseclass.h
class MyBaseClass
{
public:
  virtual void Start() = 0;
  virtual void Stop() = 0;
};
//class.h
class MyClass : public MyBaseClass
{
public:
  MyClass();
  void Stop();
};
//pointer
static MyClass *MyClassptr;
 
//myclass.cpp
MyClass::MyClass()
{
  MyClassptr=this;
}
//main.cpp
int main()
{
    MyClass MyNewClass;
    MyClassptr->Start();
    return 0;
}
Reply With Quote
  #2  
Old 07-15-2008, 01:58 AM
Junior Member
 
Join Date: Jul 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ranjittechie is on a distinguished road
| More
Smile Re: Virtual Functions and pointers

Hi,
First of all you have to define the Start() and Stop() functions.Otherwise it will take MyClass as abstract class.

After Definining these fucntions i run this same code it works fine

so try it again it works
For further queries kindly revert back
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Functions that return two values psppb C++ Programming 2 02-12-2008 10:11 PM
Reg Fucntion Pointers sowmi C++ Programming 0 06-27-2007 10:27 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:31 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board