Solved

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

Posted on 2003-11-14
19
211 Views
Last Modified: 2013-11-20
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
Comment
Question by:wjdashwood
  • 8
  • 6
  • 3
  • +1
19 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9747879
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
 
LVL 11

Expert Comment

by:KurtVon
ID: 9747884
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 9747891
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
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 100 total points
ID: 9747899
Oops. Too late.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9747905
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9747915
Hi Alex
I'm getting faster at typing <grin>
0
 

Author Comment

by:wjdashwood
ID: 9747928
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
 

Author Comment

by:wjdashwood
ID: 9748006
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9748049
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 11

Expert Comment

by:KurtVon
ID: 9748061
Nope that happens when the object isn't defined.  Make sure you include D6WebWizrdData.h before D6WebWizardDlg.h.
0
 
LVL 11

Assisted Solution

by:KurtVon
KurtVon earned 200 total points
ID: 9748065
Boy, you are getting fast at typing :-)
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9748088
Theres a lotta points here!  Good incentive!
0
 

Author Comment

by:wjdashwood
ID: 9748141
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
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 200 total points
ID: 9748165
Not in the header file.
in .h
CD6WebWizardData* m_pData;


in .cpp (eg constructor)
m_pData = new CD6WebWizardData;
0
 

Author Comment

by:wjdashwood
ID: 9748183
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
 

Author Comment

by:wjdashwood
ID: 9748334
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9748471
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
 

Author Comment

by:wjdashwood
ID: 9748598
I see, thanks for clearing that up for me. I assume I delete the pointer in the destructor of my CD6WebWizardDlg?

Cheers,
Will
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9748619
Thats a typical place to perform cleanup
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 125
notReplace  challenge 53 102
dog bark java program 15 82
twoTwo  challenge 35 86
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now