Compiling a Class in several parts?!?

Thread Solved
Reply

Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Compiling a Class in several parts?!?

 
0
  #1
Jun 29th, 2005
Hello ladies and gents,

Ive been reading about how when a class becomes to big due to to many memberfunctions, it is best to split the program up into several sections wich could be something like this:

Interface section
Implemenation section
Application section

I was given an example wich is this one, but in trying this out, I got an error message in the Implementation and Application section wich was this one:

  1. C:\Program Files\Microsoft Visual Studio\MyProjects\LATestVoorbeeldenBoekVervolg2\LATestVoorbeeldenBoekVervolg2.cpp(4) : fatal error C1083: Cannot open include file: 'vkv.h': No such file or directory
  2. Error executing cl.exe.

I know it has to do with the fact that I have to implement the "vkv.h" file into the program, problem is, I don't know how or where I have to put it :-|

The program exists out of these three parts:
  1. class vkv
  2. {
  3. private:
  4.  
  5. void coeff (double aa, double bb, double cc);
  6.  
  7. bool losOp();
  8.  
  9. double wortel1()const {return x1;}
  10. double wortel2()const {return x2;}
  11.  
  12. private:
  13.  
  14. double a, b, c, x1, x2;
  15. };
  1. #include <cmath>
  2. #include "vkv.h"
  3.  
  4. void vkv::coeff(double aa, double bb, double cc)
  5. {
  6. a = aa; b = bb; c = cc;
  7. }
  8.  
  9. bool vkv::losOp()
  10. {
  11. double D = b * b - 4 * a * c;
  12.  
  13. if (a == 0 || D < 0)
  14. return false;
  15.  
  16. double wD = sqrt(D);
  17.  
  18. x1 = (-b + wD)/(2 * a);
  19. x2 = (-b - wD)/(2 * a);
  20.  
  21. return true;
  22. }
  1. #include <iostream>
  2. #include "vkv.h"
  3.  
  4. using namespace std;
  5.  
  6. int main
  7. {
  8. double a, b, c;
  9.  
  10. cout<<"Typ a, b en c: ";
  11. cin>> a >> b >> c;
  12.  
  13. vkv v;
  14.  
  15. v.coeff(a, b, c);
  16.  
  17. if (v.losOp())
  18. cout<<"Wortels: "<< v.wortel1() <<" "<< v.wortel2() <<endl;
  19.  
  20. else
  21. cout<< "Geen reële wortels.\n";
  22.  
  23. return 0;
  24. }

I understand that the "vkv.h" headerfile is needed to link the two last sections of code so that they know they can use that file. Thing is, don't know where or HOW to put it anywhere

Do I have to put in into the Header Files map of the Workspace of the last two sections, if so, how or what do I write then
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Compiling a Class in several parts?!?

 
0
  #2
Jun 29th, 2005
Is vkv.h saved in C:\Program Files\Microsoft Visual Studio\MyProjects\LATestVoorbeeldenBoekVervolg2\?


[aside]If you still associate headers with linking and you are not using templates, then I think you have some lingering confusion.[/aside]
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: Compiling a Class in several parts?!?

 
0
  #3
Jun 29th, 2005
Hi Dave,

If added the vkv.h file towards the two last parts of the program using this path:

C:\Program Files\Microsoft Visual Studio\MyProjects\LATestVoorbeeldenBoekVervolg\vkv.h

C:\Program Files\Microsoft Visual Studio\MyProjects\LATestVoorbeeldenBoekVervolg2\vkv.h

But, in the second part, I'm getting next error messages:
  1. ATestVoorbeeldenBoekVervolg.cpp
  2. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '--'
  3. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-'
  4. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2501: 'LATestVoorbeeldenBoekVervolg' : missing storage-class or type specifiers
  5. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-'
  6. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence
  7. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence
  8. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2146: syntax error : missing ';' before identifier 'Files'
  9. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2501: 'Program' : missing storage-class or type specifiers
  10. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : fatal error C1004: unexpected end of file found
  11. Error executing cl.exe.
  12.  
  13. LATestVoorbeeldenBoekVervolg.obj - 9 error(s), 0 warning(s)

And in the third part just one error:
  1. ATestVoorbeeldenBoekVervolg2.cpp
  2. C:\Program Files\Microsoft Visual Studio\MyProjects\LATestVoorbeeldenBoekVervolg2\LATestVoorbeeldenBoekVervolg2.cpp(9) : error C2239: unexpected token '{' following declaration of 'main'
  3. Error executing cl.exe.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Compiling a Class in several parts?!?

 
0
  #4
Jun 29th, 2005
int main()
{
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: Compiling a Class in several parts?!?

 
0
  #5
Jun 29th, 2005
Yep, forgot that :rolleyes:

Also changed the mistake in the first part in wich I had written two times private!

Didn't solve the problem though, now I'm getting those error messages at part two AND part three.

  1. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '--'
  2. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-'
  3. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2501: 'LATestVoorbeeldenBoekVervolg' : missing storage-class or type specifiers
  4. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-'
  5. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence
  6. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence
  7. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2146: syntax error : missing ';' before identifier 'Files'
  8. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2501: 'Program' : missing storage-class or type specifiers
  9. c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : fatal error C1004: unexpected end of file found
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Compiling a Class in several parts?!?

 
0
  #6
Jun 29th, 2005
Is what you posted earlier currently the exact contents of the filename shown in the error message?

[edit]And you don't have a full path in the #include, do you?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: Compiling a Class in several parts?!?

 
0
  #7
Jun 29th, 2005
>>Is what you posted earlier currently the exact contents of the filename shown in the error message?

Yes.

>>And you don't have a full path in the #include, do you?

I just typed below the #include <cmath> in part two and #include <iostream> in part three the #include "vkv.h" line.

These are the programs now:
  1. // LATestVoorbeeldenBoek.cpp:
  2.  
  3. class vkv
  4. {
  5. public:
  6.  
  7. void coeff (double aa, double bb, double cc);
  8.  
  9. bool losOp();
  10.  
  11. double wortel1()const {return x1;}
  12. double wortel2()const {return x2;}
  13.  
  14. private:
  15.  
  16. double a, b, c, x1, x2;
  17. };
  1. // LATestVoorbeeldenBoekVervolg.cpp:
  2.  
  3. #include <cmath>
  4. #include "vkv.h"
  5.  
  6. void vkv::coeff(double aa, double bb, double cc)
  7. {
  8. a = aa; b = bb; c = cc;
  9. }
  10.  
  11. bool vkv::losOp()
  12. {
  13. double D = b * b - 4 * a * c;
  14.  
  15. if (a == 0 || D < 0)
  16. return false;
  17.  
  18. double wD = sqrt(D);
  19.  
  20. x1 = (-b + wD)/(2 * a);
  21. x2 = (-b - wD)/(2 * a);
  22.  
  23. return true;
  24. }
  1. // LATestVoorbeeldenBoekVervolg2.cpp:
  2.  
  3. #include <iostream>
  4. #include "vkv.h"
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. double a, b, c;
  11.  
  12. cout<<"Typ a, b en c: ";
  13. cin>> a >> b >> c;
  14.  
  15. vkv v;
  16.  
  17. v.coeff(a, b, c);
  18.  
  19. if (v.losOp())
  20. cout<<"Wortels: "<< v.wortel1() <<" "<< v.wortel2() <<endl;
  21.  
  22. else
  23. cout<< "Geen reële wortels.\n";
  24.  
  25. return 0;
  26. }

I have added the two path's that I told you and they show up in the Workspace's Header Files Map as vkv.h

In the map, they are shown as vkv.h as Type: C Header file
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Compiling a Class in several parts?!?

 
0
  #8
Jun 29th, 2005
// LATestVoorbeeldenBoek.cpp:

class vkv
{
public:

	void coeff (double aa, double bb, double cc);

	bool losOp();

	double wortel1()const {return x1;}
	double wortel2()const {return x2;}

private:

	double a, b, c, x1, x2;
};
Where's the header? I would have expected what you are calling LATestVoorbeeldenBoek.cpp to be vkv.h.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 421
Reputation: JoBe is on a distinguished road 
Solved Threads: 4
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Re: Compiling a Class in several parts?!?

 
0
  #9
Jun 29th, 2005
It is explained in this book that you take the name of the class, in this case vkv and make this into part two and three a headerfile by writing it as following:

#include "vkv.h"

All the names in the map are as follows:

LATestVoorbeeldenBoek.cpp type: C++ Source file
LATestVoorbeeldenBoek.dsp type: Project file
LATestVoorbeeldenBoek.dsw type: Project Workspace
LATestVoorbeeldenBoek.opt type: OPT-file
LAT....

I added to this map the following file:

vkv.h wich is of type: C Header file

Hope this gives you a clue as to what I'm doing wrong?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,321
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Compiling a Class in several parts?!?

 
0
  #10
Jun 29th, 2005
>Hope this gives you a clue as to what I'm doing wrong?

Sorry, no. Especially the "part two" and "part three" stuff. "Added to the map"???


http://img16.echo.cx/img16/5504/vkv9st.th.gif
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC