could you help me to debug?

N

nick

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;
}
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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)

iD8DBQFDgKK2agVFX4UWr64RAsoUAKDTmQFr3Fm5jSdNiZSiKCOtPVWP/QCfcTAT
ICLSltaBmBhMo3Ra11fat8w=
=C8JN
-----END PGP SIGNATURE-----
 
N

Nick Keighley

nick said:
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>
 
P

Peter_Julian

| 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
|
 

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,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top