| | |
Compiling a Class in several parts?!?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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:
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:
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
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)
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 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)
class vkv { private: 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; };
C++ Syntax (Toggle Plain Text)
#include <cmath> #include "vkv.h" void vkv::coeff(double aa, double bb, double cc) { a = aa; b = bb; c = cc; } bool vkv::losOp() { double D = b * b - 4 * a * c; if (a == 0 || D < 0) return false; double wD = sqrt(D); x1 = (-b + wD)/(2 * a); x2 = (-b - wD)/(2 * a); return true; }
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "vkv.h" using namespace std; int main { double a, b, c; cout<<"Typ a, b en c: "; cin>> a >> b >> c; vkv v; v.coeff(a, b, c); if (v.losOp()) cout<<"Wortels: "<< v.wortel1() <<" "<< v.wortel2() <<endl; else cout<< "Geen reële wortels.\n"; return 0; }
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
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]
[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
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:
And in the third part just one error:
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)
ATestVoorbeeldenBoekVervolg.cpp c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '--' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2501: 'LATestVoorbeeldenBoekVervolg' : missing storage-class or type specifiers c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2146: syntax error : missing ';' before identifier 'Files' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2501: 'Program' : missing storage-class or type specifiers c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : fatal error C1004: unexpected end of file found Error executing cl.exe. LATestVoorbeeldenBoekVervolg.obj - 9 error(s), 0 warning(s)
And in the third part just one error:
C++ Syntax (Toggle Plain Text)
ATestVoorbeeldenBoekVervolg2.cpp C:\Program Files\Microsoft Visual Studio\MyProjects\LATestVoorbeeldenBoekVervolg2\LATestVoorbeeldenBoekVervolg2.cpp(9) : error C2239: unexpected token '{' following declaration of 'main' Error executing cl.exe.
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
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.
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)
c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '--' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2501: 'LATestVoorbeeldenBoekVervolg' : missing storage-class or type specifiers c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(1) : error C2143: syntax error : missing ';' before '-' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2017: illegal escape sequence c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2146: syntax error : missing ';' before identifier 'Files' c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : error C2501: 'Program' : missing storage-class or type specifiers c:\program files\microsoft visual studio\myprojects\latestvoorbeeldenboekvervolg\vkv.h(4) : fatal error C1004: unexpected end of file found
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?
[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
>>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:
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
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)
// 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; };
C++ Syntax (Toggle Plain Text)
// LATestVoorbeeldenBoekVervolg.cpp: #include <cmath> #include "vkv.h" void vkv::coeff(double aa, double bb, double cc) { a = aa; b = bb; c = cc; } bool vkv::losOp() { double D = b * b - 4 * a * c; if (a == 0 || D < 0) return false; double wD = sqrt(D); x1 = (-b + wD)/(2 * a); x2 = (-b - wD)/(2 * a); return true; }
C++ Syntax (Toggle Plain Text)
// LATestVoorbeeldenBoekVervolg2.cpp: #include <iostream> #include "vkv.h" using namespace std; int main() { double a, b, c; cout<<"Typ a, b en c: "; cin>> a >> b >> c; vkv v; v.coeff(a, b, c); if (v.losOp()) cout<<"Wortels: "<< v.wortel1() <<" "<< v.wortel2() <<endl; else cout<< "Geen reële wortels.\n"; return 0; }
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
•
•
•
•
// 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; };
"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
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?
#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?
>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
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
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Unable to use system commands for turbo c++ 3.0 on win-XP
- Next Thread: Help figuring Obj. Oriented programing
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






