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

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;
};
#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;
}
#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]

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:

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:

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()
{

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:\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?

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

// 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;
};
// 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;
}
// 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;
};

Where's the header? I would have expected what you are calling LATestVoorbeeldenBoek.cpp to be vkv.h.

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?

In the top picture it looks like compile progress is in your vkv.h file. Your class declaration is in LATestVoorBeeldenBoek.cpp -- it should be in you vkv.h.

The popup seems to indicate that you were attempting to compile a header. You don't click on 'compile' for a header.

>> The popup seems to indicate that you were attempting to compile a header. You don't click on 'compile' for a header.

Then when I create that Header file vkv.h, I just write the code and save it as a Header File?

Also, you have a map called 'External Dependencies', instead of putting the Header file in there, can I just put it in the map 'Header files'?

I notice that in your Source Files for Sample PP, there are two .cpp files, main.cpp and vkv.cpp, did you add these to the vkv.h header file?

Did you add any files towards the main.cpp or/and vkv.cpp?

I have deleted the different programs and will make a new attempt tommorow, I printed you're example so I have an idea what it should look like ;)

Thanks for your patience Dave, very much appreciated :!:

>Then when I create that Header file vkv.h, I just write the code and save it as a Header File?

I think so -- I'm not familiar with that editor. I usually just save a file as whatever.h.

>Also, you have a map called 'External Dependencies', instead of putting the Header file in there, can I just put it in the map 'Header files'?

I didn't put anything anywhere. When the compiler found files that were #included, it listed them there.

>I notice that in your Source Files for Sample PP, there are two .cpp files, main.cpp and vkv.cpp, did you add these to the vkv.h header file?

I added the source files to the project.

>Did you add any files towards the main.cpp or/and vkv.cpp?

No.

Good to hear.

Describing the process of creating project using multiple source files is not the easiest thing to do!

I understand, neither is trying to explain something what's wrong without being able to show it.

But like I said, with what you told me then showing me how you did it with the picture, I just deleted the previous one and started again.

I didn't compile the headerfile vkv.h and after creating the other source files and compiling them, the headerfile automatically was added towards the program :D

Thing with these items is, that once you have seen how it is supposed to be done, it isn't difficult at all, but, problem is, you have to be able to let it succeed ONE TIME :lol:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.