944,103 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2601
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 29th, 2005
0

Compiling a Class in several parts?!?

Expand Post »
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:

C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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. };
C++ Syntax (Toggle Plain Text)
  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. }
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

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]
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

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:
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

int main()
{
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

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.

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

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?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

>>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:
C++ Syntax (Toggle Plain Text)
  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. };
C++ Syntax (Toggle Plain Text)
  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. }
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

Quote ...
// 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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

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?
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
Jun 29th, 2005
0

Re: Compiling a Class in several parts?!?

>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
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Unable to use system commands for turbo c++ 3.0 on win-XP
Next Thread in C++ Forum Timeline: Help figuring Obj. Oriented programing





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC