GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-May-2004, 03:19
Melvin Lin Melvin Lin is offline
New Member
 
Join Date: Mar 2004
Posts: 16
Melvin Lin is on a distinguished road

Static Class Member Accessing


Dose anybody help me, please!
See the following attatched program code(Cam.h and Cam.cpp)
What I want to ask is how should I access the "data" of private class member "m_Image"?

Please focus on following code:
CPP / C++ / C Code:
//Begin code
void cCam::camCallback(IplImage* image)
{
m_Image = (IplImage*)image;

return;
}
//End code

/************************************************** 
Cam.h
by Sylvia (03 Mar 2004)

Modified 
************************************************** /

#pragma once

#include <cv.h> // include core library interface
#include <highgui.h> // include GUI library interface
#include "cvcam.h"

class cCam
{
private:
HWND m_hWnd;

int m_ResW;
int m_ResH;

IplImage *m_Image;

static void camCallback(IplImage* image);

public:
cCam(void);
~cCam(void);

BOOL Init(HWND hwnd, int width=320, int height=240);
BOOL Shutdown();
};



/************************************************** 
Cam.cpp
by Sylvia (03 Mar 2004)

Modified 
************************************************** /
#include "cam.h"

cCam::cCam(void)
{
}

cCam::~cCam(void)
{
Shutdown();
}

BOOL cCam::Init(HWND hwnd, int width, int height)
{
cvcamStop();
cvcamExit();

//NO CAMERAS FOUND !
if (cvcamGetCamerasCount() == 0 )
{
::MessageBox(NULL, "No Cameras found!", "Error Message", MB_ICONWARNING|MB_OK);
return FALSE;
}

if((m_hWnd = hwnd) == NULL)
return FALSE;

int webcamNo =0;
m_ResW = width;
m_ResH = height;

cvcamSetProperty(0, CVCAM_RNDWIDTH, &m_ResW); //Set resolution
cvcamSetProperty(0, CVCAM_RNDHEIGHT, &m_ResH);

cvcamSetProperty(0, CVCAM_PROP_ENABLE, &webcamNo); //Selects the 1-st found camera 
cvcamSetProperty(0, CVCAM_PROP_RENDER, &webcamNo); //We will render stream from this source

cvcamSetProperty(0, CVCAM_PROP_WINDOW, &m_hWnd); // Selects a window for video rendering

cvcamSetProperty(0, CVCAM_PROP_CALLBACK, camCallback); //this callback will process every frame 
//the programe still work without this statement
//if comment this statement, the frame will become color
cvcamInit();
cvcamStart();

return TRUE;
}

BOOL cCam::Shutdown()
{
cvcamStop();
cvcamExit();

return TRUE;
}

void cCam::camCallback(IplImage* image)
{
m_Image = (IplImage*)image;

return;
}
Attached Images
File Type: gif Cam.h.gif (22.9 KB, 85 views)
File Type: gif Cam1.cpp.gif (45.1 KB, 74 views)
File Type: gif Cam2.cpp.gif (10.6 KB, 94 views)
Last edited by dsmith : 03-May-2004 at 08:14. Reason: Please use [c] & [/c] when posting C++ code
  #2  
Old 03-May-2004, 04:33
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Since the member is a pointer, you must use pointer notation to access it.

CPP / C++ / C Code:
int main()
{
  cCam myObject;
  IplImage myImage

  // This would work, assuming the image pointer was a public member. Since
  // it isn't, you will only be able to access it in this manner using member
  // functions.
  
  cCam->image = myImage; // Notice the little -> is used instead of a dot.

  return 0;
}
This is what I initially interpreted you to be asking about, but now that I look at it, I'm not really sure what you're having a problem with. Could you please explain where you're running into a problem, give the specific error produced by the compiler, and also give any other details that might be relevant to the problem? Also, please refer to this page for information on how to enable code formatting and syntax hi-lighting in your posts. Thank you!
__________________
-Aaron
  #3  
Old 03-May-2004, 06:12
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
use a friend function in your class to access private data from outside the class
  #4  
Old 03-May-2004, 10:39
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Also, don't post new threads on the same code. You are allowed to ask more than one question per post/thread. Saves time and confusion.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #5  
Old 03-May-2004, 12:35
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
I wasn't aware that he posted this code in another thread. If he didn't create the original thread that contained this code, that would be why I haven't seen it, but I don't see any threads created for the purpose of getting help with this code other than the one I'm currently posting in...
__________________
-Aaron
  #6  
Old 03-May-2004, 12:36
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
haha this reminds me of aaron's thread which i think was the most read and replied to in this forum other than the sticky and aaron thought nobody respected him
  #7  
Old 03-May-2004, 12:41
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Yeah, but I don't know why! I didn't post my code in two different threads... or did the thing with the friend function remind you of it? It's odd that friend functions would come up twice in such a short interval of time when it hadn't come up once previously... :-P
__________________
-Aaron
  #8  
Old 03-May-2004, 12:43
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
FYI: This topic was posted in another GID Forum and then moved to here by another mod. I have since deleted the thread. So before this gets out of hand, Walt and Aaron are both correct
  #9  
Old 03-May-2004, 13:27
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
Quote:
Originally Posted by aaroncohn
Yeah, but I don't know why! I didn't post my code in two different threads... or did the thing with the friend function remind you of it? It's odd that friend functions would come up twice in such a short interval of time when it hadn't come up once previously... :-P


yeah i meant friend function thing we just recently beat the friends to death! thats why when i replied to this post, i just posted a one line suggestion : use friend function lol
  #10  
Old 03-May-2004, 14:44
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Well I wouldn't say we beat it to death... although, when I have a question, the subject does tend to be beaten!
__________________
-Aaron
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with class functions Mjkramer21 C++ Forum 2 23-Apr-2004 09:23
[You Decide] - What is the colour for Member: Level 5 JdS GIDForums™ 5 17-Mar-2004 05:14
Upgrade of BBCode class sometime today JdS GIDForums™ 4 03-Nov-2003 08:18
need help to define a class in C++ yannoush C++ Forum 7 09-Sep-2003 01:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:53.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.