could you help me to debug?

Discussion in 'C Programming' started by nick, Nov 20, 2005.

  1. nick

    nick Guest

    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;
    }
     
    nick, Nov 20, 2005
    #1
    1. Advertising

  2. nick

    Lew Pitcher Guest

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

    iD8DBQFDgKK2agVFX4UWr64RAsoUAKDTmQFr3Fm5jSdNiZSiKCOtPVWP/QCfcTAT
    ICLSltaBmBhMo3Ra11fat8w=
    =C8JN
    -----END PGP SIGNATURE-----
     
    Lew Pitcher, Nov 20, 2005
    #2
    1. Advertising

  3. 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
     
    Nick Keighley, Nov 20, 2005
    #3
  4. nick

    Peter_Julian Guest

    "Nick Keighley" <> wrote in message
    news:...
    | 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
    |
     
    Peter_Julian, Nov 20, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Gagon

    If you could add anything you want

    John Gagon, May 12, 2006, in forum: Java
    Replies:
    55
    Views:
    1,436
    Oliver Wong
    May 25, 2006
  2. Shawn
    Replies:
    8
    Views:
    401
    Shawn
    Sep 21, 2006
  3. Jon Harrop
    Replies:
    2
    Views:
    337
    Roedy Green
    Jul 17, 2007
  4. Alexander
    Replies:
    620
    Views:
    8,641
    Seebs
    Nov 9, 2010
  5. Alexander
    Replies:
    68
    Views:
    1,575
Loading...

Share This Page