By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,292 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Jason" <ja***********@btinternet.com> wrote in message
news:bt**********@hercules.btinternet.com...
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.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #2

P: n/a
Hello,

"Jason" <ja***********@btinternet.com> writes:
#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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #3

P: n/a


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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.