• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Help with splitting class into 2, transferring member functions to new class

Hi

Can anyone guide me through copying some existing functions from my CD6WebWizardDlg class to my new CD6WebWizardData class I created using the class wizard (or whatever the equivalent is in VS 2003)? I've made all the member functions and variables of CD6WebWizardData public but when they are called from CD6WebWizardDlg the identifier is not found.

I've included "D6WebWizardData.h" in D6WebWizardDlg.cpp and D6WebWizard.cpp. I was expecting to just type "CD6WebWizardData->" and IntelliSense would show me the list of member functions and variables but it doesn't and expects ';' before '->'.

Any help would be appreciated. I've always had wizards to help me with classes so I've never really got to grips with them 100%.

Thanks,
Will
http://wjdashwood.co.uk/
0
wjdashwood
Asked:
wjdashwood
  • 8
  • 6
  • 3
  • +1
3 Solutions
 
AndyAinscowCommented:
try
CD6WebWizardData data;
then
data.
to see if intellisense shows you the functions and variables

or the equivalent with a pointer to a CD6WebWizardData object
0
 
KurtVonCommented:
Shouldn't you be using a variable name for the pointer, not the class name?

CD6WebWizardData* pData;
pData = new CD6WebWizardData;
pData->MemberFunction();

Hope this helps.
0
 
AlexFMCommented:
You need to creare CD6WebWizardData instance or pointer:

CD6WebWizardData m_Data;
CD6WebWizardData m_pData;

Now when you type
p_Data.
or
m_pData->

you have IntelliSense list of class members.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AlexFMCommented:
Oops. Too late.
0
 
AndyAinscowCommented:
To copy functions just use the editor.
I would suggest cuttin/pasting the contents from the cpp files first (so you can still double click on the class explorer view to spring to a function you haven't transferred) and then the appropriate lines in the .h files.
0
 
AndyAinscowCommented:
Hi Alex
I'm getting faster at typing <grin>
0
 
wjdashwoodAuthor Commented:
Thanks guys! I deserve a good slap in the face for missing out on the very obvious! I'll get it working then come back and give out points.

Cheers,
Will
0
 
wjdashwoodAuthor Commented:
Perhaps not as plain sailing as I thought. The compiler doesn't like :

protected:
      CD6WebWizardData* pData;

error C2143: syntax error : missing ';' before '*'

Have I put it in the wrong place? Interestingly though, IntelliSense works!
0
 
AndyAinscowCommented:
Have you included the .h file that has the CD6WebWizardData in it?

or in your header file near the top add the line
class CD6WebWizardData;
which is a forward declaration.
You would need the header included in your cpp file for the second way
0
 
KurtVonCommented:
Nope that happens when the object isn't defined.  Make sure you include D6WebWizrdData.h before D6WebWizardDlg.h.
0
 
KurtVonCommented:
Boy, you are getting fast at typing :-)
0
 
AndyAinscowCommented:
Theres a lotta points here!  Good incentive!
0
 
wjdashwoodAuthor Commented:
Right, one problem down, another to go!

m_pData = new CD6WebWizardData;

error C2864: 'm_pData' : only const static integral data members can be initialized inside a class or struct
0
 
AndyAinscowCommented:
Not in the header file.
in .h
CD6WebWizardData* m_pData;


in .cpp (eg constructor)
m_pData = new CD6WebWizardData;
0
 
wjdashwoodAuthor Commented:
Aha! Once again problem solved and all is right with the world. Thanks for all your help. Just for the record, which is best to do; create an instance or a pointer? What's the difference?
0
 
wjdashwoodAuthor Commented:
No one so keen on answering that one? Never mind, not important. I assume that creating a new instance makes a copy of the class instead of referring to the original. Now I have to try and share points out fairly! Eek.
0
 
AndyAinscowCommented:
I've just been taking the kids out for a walk so didn't see the question.
'which is best to do; create an instance or a pointer? What's the difference? '

One is on the heap the other on the stack.  In the old days where memory was precious it could make quite a difference.  In reality for most situations now it probably doesn't make that much difference.  Having said that creating a pointer object with new requires you to delete it yourself so a bit of extra code to tidy up (and a not uncommon problem of invalid pointers when cleaned up too soon!).
0
 
wjdashwoodAuthor Commented:
I see, thanks for clearing that up for me. I assume I delete the pointer in the destructor of my CD6WebWizardDlg?

Cheers,
Will
0
 
AndyAinscowCommented:
Thats a typical place to perform cleanup
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now