method returning a pointer to a structure

This is a discussion on method returning a pointer to a structure within the C++ Programming forums, part of the General Programming Boards category; Hi... I am quite new to C++ (but no to programming or OOP) so, I have some questions specific to ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126

    Question method returning a pointer to a structure

    Hi...
    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)
    Code:
    #include "cv.h" 
    #include "highgui.h"
    class CylindricalWarper{
    	private:
    	float fx,fy; //focal lenght
    	float cx,cy; //optical center
    	float k1,k2; //radial distorition coeficients
    	public:
    	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
    Code:
    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.
    Regards
    Ignacio.


    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
    Posts
    14,185
    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
    Location
    japan
    Posts
    126
    pretty fast!,
    Thanks.
    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?

    Code:
    class CAboutDlg : public CDialog
    {
    public:
    	CAboutDlg();
    
    // Dialog Data
    	enum { IDD = IDD_ABOUTBOX };
    
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    
    // Implementation
    protected:
    	DECLARE_MESSAGE_MAP()
    };
    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
    dra
    dra is offline
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    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, 03:58 PM
  2. Replies: 2
    Last Post: 01-22-2008, 03: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 Cprogramming.com
    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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21