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

could you help me to debug?

P: n/a
the following code is copy from a file called "abc.cpp"
i can compile it suscessfully, but an error occur when i run it
the error message is
--------------------Configuration: abc - Debug--------------------
Linking...
C:\abc.o(.text+0x59): In function `main':
C:\abc.cpp:14: undefined reference to `abc::abc()'

abc.exe - 1 error(s), 0 warning(s)

why?
thanks!

#include<iostream>
using namespace std;
class abc{
public:
abc();
void test();
};

void abc::test(){
cout<<"Testing"<<endl;
}

int main(int argc, char *argv[]){
abc a;
a.test();

return 0;
}
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

nick wrote:
the following code is copy from a file called "abc.cpp"
The name of your program is the first clue to the error
i can compile it suscessfully, but an error occur when i run it
the error message is
--------------------Configuration: abc - Debug--------------------
Linking...
C:\abc.o(.text+0x59): In function `main':
C:\abc.cpp:14: undefined reference to `abc::abc()'

abc.exe - 1 error(s), 0 warning(s)

why?
thanks!

#include<iostream>

And here's another

You have at least one big problem. You are asking a C++ compilation question
in a group that does not discuss C++. comp.lang.c is dedicated to discussion
of program development in standards-compliant C language, and has nothing to
do with C++

You might try asking your question in comp.lang.c++, which is just down the
hall - second door on the right, just past the water cooler.

Otherwise, you need to ask in a group dedicated to your specific
compiler/operating environment - you'll likely find them in upstairs - four
flights up.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFDgKK2agVFX4UWr64RAsoUAKDTmQFr3Fm5jSdNiZSiKC OtPVWP/QCfcTAT
ICLSltaBmBhMo3Ra11fat8w=
=C8JN
-----END PGP SIGNATURE-----
Nov 20 '05 #2

P: n/a
nick wrote:
the following code is copy from a file called "abc.cpp"
i can compile it suscessfully, but an error occur when i run it
the error message is
--------------------Configuration: abc - Debug--------------------
Linking...
C:\abc.o(.text+0x59): In function `main':
C:\abc.cpp:14: undefined reference to `abc::abc()'

abc.exe - 1 error(s), 0 warning(s)

why?
thanks!

#include<iostream>
using namespace std;
class abc{
public:
abc();
void test();
};

void abc::test(){
cout<<"Testing"<<endl;
}

int main(int argc, char *argv[]){
abc a;
a.test();

return 0;
}


comp.lang.c is a forum for the discussion of the C language. You have
posted a
C++ program. You should ask C++ questions on comp.lang.c++.

<off topic>
as your compiler suggested you have no definition for the function
abc()
<end>
--
Nick Keighley

Nov 20 '05 #3

P: n/a

"Nick Keighley" <ni******************@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
| nick wrote:
|
| > the following code is copy from a file called "abc.cpp"
| > i can compile it suscessfully, but an error occur when i run it
| > the error message is
| > --------------------Configuration: abc - Debug--------------------
| > Linking...
| > C:\abc.o(.text+0x59): In function `main':
| > C:\abc.cpp:14: undefined reference to `abc::abc()'
| >
| > abc.exe - 1 error(s), 0 warning(s)
| >
| > why?
| > thanks!
| >
| > #include<iostream>
| > using namespace std;
| > class abc{
| > public:
| > abc();
| > void test();
| > };

Where is the abc ctor defined? Thats exactly what the compiler is asking
you. Since you've decared a ctor, you've told the compiler not to
generate a default ctor, therefore, its looking for your abc::abc()
definition.

By the way, its convention that a struct or class by capitalized in
order to help you identify the type and the instances of the type.

class A
{
public:
A() { }
~A() { }
};

int main()
{
A a;
}

| >
| > void abc::test(){
| > cout<<"Testing"<<endl;
| > }

That function should have been declared in the class declaration as

void test() const;

....since its not modifying the instance of that class in any way.
(void test() does not require the presence of the "this" pointer)

| >
| > int main(int argc, char *argv[]){
| > abc a;
| > a.test();
| >
| > return 0;
| > }
|
| comp.lang.c is a forum for the discussion of the C language. You have
| posted a
| C++ program. You should ask C++ questions on comp.lang.c++.
|
| <off topic>
| as your compiler suggested you have no definition for the function
| abc()
| <end>
|
|
| --
| Nick Keighley
|
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.