how to solve C2084 error.

Jan 29, 2013 at 4:50pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void line_equal()
{
	cout<<"\n\t\t";
	for(int i=1;i<=58;i++)
		cout<<"=";
	cout<<"\n";
}
void line_star_small()
{
	cout<<"\n\t\t";
	for(int i=0;i<=40;i++)
		cout<<"*";
	cout<<"\n";
}

how to solve the "funcion already has a body"?
Jan 29, 2013 at 4:58pm
i am accessing this header file from many header files...
Jan 29, 2013 at 4:59pm
The problem is somewhere else, this code snipped is fine.
Do you include some custom headers? And do they by chance have no header guards? Or mayby functions implemented in header?
Last edited on Jan 29, 2013 at 5:02pm
Jan 29, 2013 at 5:11pm
functions are implemented in also a header file and access is also from header files...
Jan 29, 2013 at 5:12pm
header.h
1
2
3
4
5
6
7
#ifndef headerH
#define headerH

void line_equal();
void line_star_small();

#endif 


header.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include "header.h"

void line_equal()
{
	std::cout<<"\n\t\t";
	for(int i=1;i<=58;i++)
		std::cout<<"=";
	std::cout<<"\n";
}

void line_star_small()
{
	std::cout<<"\n\t\t";
	for(int i=0;i<=40;i++)
		std::cout<<"*";
	std::cout<<"\n";
}


main.cpp
1
2
3
4
5
6
7
8
9
#include "header.h"

int main()
{

    line_star_small();

    return 0;
}
Last edited on Jan 29, 2013 at 5:19pm
Jan 29, 2013 at 5:38pm
its working but tell me how..??
Jan 29, 2013 at 5:51pm
Well, the .h file contains just the function prototypes. You can include that in as many other files as you like. It simply lets the compiler know that the function exists somewhere, and what parameters it takes and returns.

However, the function definition in the .cpp file can appear only once, otherwise the compiler/linker won't know which version to choose from.
Jan 29, 2013 at 6:14pm
I also put functions Definations in a header file what is the wrong?
Jan 29, 2013 at 6:16pm
It's not really possible to say what's wrong without seeing more of your code, and what files there are, which file is including which other one etc...
Jan 29, 2013 at 6:29pm
The file header.h plz tell me which are the keywords and which one can i change
Jan 30, 2013 at 11:40am
This article may help: "Headers and Includes: Why and How"
http://www.cplusplus.com/articles/Gw6AC542/
Topic archived. No new replies allowed.