Solved

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

Posted on 2003-11-14
19
218 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 49
ODBC Connection Logging, ADO.NET 6 64
Smart Camera scanning and reading information 3 106
twoTwo  challenge 35 102
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…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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