how to solve C2084 error.

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"?
i am accessing this header file from many header files...
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
functions are implemented in also a header file and access is also from header files...
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
its working but tell me how..??
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.
I also put functions Definations in a header file what is the wrong?
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...
The file header.h plz tell me which are the keywords and which one can i change
This article may help: "Headers and Includes: Why and How"
http://www.cplusplus.com/articles/Gw6AC542/
Topic archived. No new replies allowed.