Thread: method returning a pointer to a structure

  1. #1
    Registered User
    Join Date
    Nov 2006

    Question method returning a pointer to a structure

    I am quite new to C++ (but no to programming or OOP) so, I have some questions specific to C++ syntax, etc I hope you can help me as you did when I was trying to learn C

    I have a Class like: (I am using the C based openCV library)
    (IplImage is a structure so I want to get returned a pointer to the structure created inside each method, This would have perfect sense in Objective-C)
    #include "cv.h" 
    #include "highgui.h"
    class CylindricalWarper{
    	float fx,fy; //focal lenght
    	float cx,cy; //optical center
    	float k1,k2; //radial distorition coeficients
    	void InitInstance(CString cameraString);
    	IplImage * CorrectDistortion(IplImage *image);
    	IplImage * CylindricalWarp(IplImage *undistorted);
    And My questions are
    1. Do I need a SuperClass? (ie: class CylindricalWarper:Warper{... )or is up to me?
    and what is the most basic Class (which all objects inherit from) in C++

    2. When I compile it I got two errors: error C2440: 'initializing' : cannot convert from 'void *' to 'IplImage *'
    Each one in the first line inside CorrectDistortion method and CylindricalWarp method.
    I think it is not just like C when you write something like
    IplImage * correctDistortion(IplImage *);
    What is the correct way?

    3. What is the meaning and what is used for the word "virtual" ?

    Any response would be very appreciated.

    PD: this task could be accomplished without classes but just for learning purposes I decided to make such a class
    Mac OS 10.6 Snow Leopard : Darwin

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    1. There is no C++ analogue to Object or whatever; there is no overarching base class that everything is a member of.

    2. Are you asking whether you need a superclass (which is what you say) or a constructor (which is what you show)?

    3. In C++ you must cast all your pointers explicitly from void * to whatever *; it doesn't happen automatically.

    4. virtual means "this function might be overridden by an inheriting class, so check first".

  3. #3
    Registered User
    Join Date
    Nov 2006
    pretty fast!,
    to tabstop:
    For 1 and 2, I meant when writting the definition of the class:
    I don't need to specify what class is inheriting from? (I mean if is mandatory or not... it seems not to be mandatory right?)

    I just got this part from a MFC project I am doing and as you see CAAboutDlg is inheriting from CDialog, that is why I asked if all the classes I make should have a parent?

    class CAboutDlg : public CDialog
    // Dialog Data
    	enum { IDD = IDD_ABOUTBOX };
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    // Implementation
    3 I just solved the error, sorry it was an opencv library usage mistake, so not regarding c++
    4 thanks this is very clear now
    Mac OS 10.6 Snow Leopard : Darwin

  4. #4
    Weak. dra's Avatar
    Join Date
    Apr 2005
    There is no underlying "base" class that all classes must inherit from in C++ as tabstop said. In MFC, classes like CDialog are provided as "foundations" that allow the programmer to build upon them instead of working straight from the ground up, hence the inheritance.
    Last edited by dra; 05-25-2009 at 10:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dereferencing a Void Pointer in a Structure
    By simpsonseric in forum C Programming
    Replies: 5
    Last Post: 01-17-2009, 04:58 PM
  2. Replies: 2
    Last Post: 01-22-2008, 04:22 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Pointer to next Structure
    By Garfield in forum C Programming
    Replies: 6
    Last Post: 09-16-2001, 03:18 PM

Tags for this Thread