implicit declaration of function 'int func(...)' error

J

Jason

Hi,

Im running windows xp pro and compiling using dev c++ 4. I have the
following situation:

#include <iostream>
#include <string>
using namespace std;

int main() {
string str;
func(str);
}

void func(string str) {
//do stuff, call some other classes member functions etc
func2(str);
}

void func2(string str) {
//do more stuff
}

It says 2 errors occur with the following output:

7 errormain.cpp
implicit declaration of function `int func(...)'
7 errormain.cpp
warning: cannot pass objects of type `string' through `...'
12 errormain.cpp
implicit declaration of function `int func2(...)'
12 errormain.cpp
warning: cannot pass objects of type `string' through `...'

What am I doing wrong???

Thanks for any help in advance
jason
 
S

Sumit Rajan

Jason said:
Hi,

Im running windows xp pro and compiling using dev c++ 4. I have the
following situation:

#include <iostream>
#include <string>
using namespace std;

void func(string str);
void func2(string str);

int main() {
string str;
func(str);
}

void func(string str) {
//do stuff, call some other classes member functions etc
func2(str);
}

void func2(string str) {
//do more stuff
}

It says 2 errors occur with the following output:

7 errormain.cpp
implicit declaration of function `int func(...)'
7 errormain.cpp
warning: cannot pass objects of type `string' through `...'
12 errormain.cpp
implicit declaration of function `int func2(...)'
12 errormain.cpp
warning: cannot pass objects of type `string' through `...'

What am I doing wrong???

Or you could try rearranging the code:

#include <iostream>
#include <string>
using namespace std;

void func2(string str) {
//do more stuff
}

void func(string str) {
//do stuff, call some other classes member functions etc
func2(str);
}

int main() {
string str;
func(str);
}


Regards,
Sumit.
 
C

Chris Dams

Hello,

Jason said:
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
func(str);
}
void func(string str) {
//do stuff, call some other classes member functions etc
func2(str);
}
void func2(string str) {
//do more stuff
}
It says 2 errors occur with the following output:
7 errormain.cpp
implicit declaration of function `int func(...)'

The declaration and/or definition of func must come before its first use.
The solution is to either put the entire definition in front of main or to
leave it at its current position but then you have to put

void func(string);

before the first use of func.
7 errormain.cpp
warning: cannot pass objects of type `string' through `...'

This error will disappear after you fixed the previous one.
12 errormain.cpp
implicit declaration of function `int func2(...)'

Same as previous error. func2 should be declared and/or defined before
first use.
12 errormain.cpp
warning: cannot pass objects of type `string' through `...'

Good luck and a happy 2004,
Chris Dams
 
T

Thomas Mang

Jason said:
Hi,

Im running windows xp pro and compiling using dev c++ 4. I have the
following situation:

#include <iostream>
#include <string>
using namespace std;

int main() {
string str;
func(str);
}

void func(string str) {
//do stuff, call some other classes member functions etc
func2(str);
}

void func2(string str) {
//do more stuff
}

It says 2 errors occur with the following output:

7 errormain.cpp
implicit declaration of function `int func(...)'

Not a particular useful error message for inexperienced users.

The problem is at the point you call "func" in main and "func2" in func,
these functions are not known to the compiler yet.

Add these 2 lines before main (to declare "func" and "func2"), and
everything should compile fine:

void func(string str);
void func2(string str);


BTW, why do you pass the std::string by value? Usually, it is passed as
const reference (for efficiency reasons).


regards,

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top