Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Leaning C++, annoying compile/link error

Leaning C++, annoying compile/link error

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpannouncementlearning
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jan Sommer
    wrote on last edited by
    #1

    I've managed to compile and run all the samples in the book so far, but all the sudden this code comes up and gives me nasty headaches. When i'm trying to compile the code below everything goes fine until the compiler tries to link it. Here's the error i get: cd /Users/summer/Documents/C++/xcodeproject/ex /Developer/usr/bin/g++-4.0 -o /Users/summer/Documents/C++/xcodeproject/ex/build/Debug/ex -L/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -F/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -filelist /Users/summer/Documents/C++/xcodeproject/ex/build/ex.build/Debug/ex.build/Objects-normal/i386/ex.LinkFileList -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk Undefined symbols: "vtable for Kvadrat", referenced from: __ZTV7Kvadrat$non_lazy_ptr in main.o ld: symbol(s) not found collect2: ld returned 1 exit status "vtable for Kvadrat", referenced from: __ZTV7Kvadrat$non_lazy_ptr in main.o ld: symbol(s) not found collect2: ld returned 1 exit status And here's the code:

    #include
    using namespace std;

    class Form
    {
    public:
    Form() {}
    virtual ~Form() {}
    virtual long HentAreal() { return -1; }
    virtual long HentOmkreds() { return -1; }
    virtual void Tegn() {}
    };

    class Rektangel : public Form
    {
    public:
    Rektangel(int laengde, int bredde):
    densLaengde(laengde), densBredde(bredde) {}
    virtual ~Rektangel() {}
    virtual long HentAreal() { return densLaengde * densBredde; }
    virtual long HentOmkreds() { return 2*densLaengde + 2*densBredde; }
    virtual int HentLaengde() { return densLaengde; }
    virtual int HentBredde() { return densBredde; }
    virtual void Tegn();
    private:
    int densBredde;
    int densLaengde;
    };

    void Rektangel::Tegn()
    {
    for (int i = 0;i < densLaengde;i++)
    {
    for (int j = 0;j < densBredde;j++)
    cout << "x";

    	cout << "\\n";
    }
    

    }

    class Kvadrat : public Rektangel
    {
    public:
    Kvadrat(int laengde);
    Kvadrat(int laengde, int bredde);
    ~Kvadrat();
    long HentOmkreds() { return 4 * HentLaengde(); }
    };

    Kvadrat::Kvadrat(int laengde):
    Rektangel(laengde, laengde)
    {}

    int main()
    {
    cout << "Do stuff";
    return 0;
    }

    When i remove Kvadrat::Kvadrat(int laengde): Rektangel(laengde, laengde) {} It compiles without problems. But i want to create a rectangel upon creation of a square! (rektangel == rectangel && kvadrat == square in danish)

    D CPalliniC 2 Replies Last reply
    0
    • J Jan Sommer

      I've managed to compile and run all the samples in the book so far, but all the sudden this code comes up and gives me nasty headaches. When i'm trying to compile the code below everything goes fine until the compiler tries to link it. Here's the error i get: cd /Users/summer/Documents/C++/xcodeproject/ex /Developer/usr/bin/g++-4.0 -o /Users/summer/Documents/C++/xcodeproject/ex/build/Debug/ex -L/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -F/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -filelist /Users/summer/Documents/C++/xcodeproject/ex/build/ex.build/Debug/ex.build/Objects-normal/i386/ex.LinkFileList -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk Undefined symbols: "vtable for Kvadrat", referenced from: __ZTV7Kvadrat$non_lazy_ptr in main.o ld: symbol(s) not found collect2: ld returned 1 exit status "vtable for Kvadrat", referenced from: __ZTV7Kvadrat$non_lazy_ptr in main.o ld: symbol(s) not found collect2: ld returned 1 exit status And here's the code:

      #include
      using namespace std;

      class Form
      {
      public:
      Form() {}
      virtual ~Form() {}
      virtual long HentAreal() { return -1; }
      virtual long HentOmkreds() { return -1; }
      virtual void Tegn() {}
      };

      class Rektangel : public Form
      {
      public:
      Rektangel(int laengde, int bredde):
      densLaengde(laengde), densBredde(bredde) {}
      virtual ~Rektangel() {}
      virtual long HentAreal() { return densLaengde * densBredde; }
      virtual long HentOmkreds() { return 2*densLaengde + 2*densBredde; }
      virtual int HentLaengde() { return densLaengde; }
      virtual int HentBredde() { return densBredde; }
      virtual void Tegn();
      private:
      int densBredde;
      int densLaengde;
      };

      void Rektangel::Tegn()
      {
      for (int i = 0;i < densLaengde;i++)
      {
      for (int j = 0;j < densBredde;j++)
      cout << "x";

      	cout << "\\n";
      }
      

      }

      class Kvadrat : public Rektangel
      {
      public:
      Kvadrat(int laengde);
      Kvadrat(int laengde, int bredde);
      ~Kvadrat();
      long HentOmkreds() { return 4 * HentLaengde(); }
      };

      Kvadrat::Kvadrat(int laengde):
      Rektangel(laengde, laengde)
      {}

      int main()
      {
      cout << "Do stuff";
      return 0;
      }

      When i remove Kvadrat::Kvadrat(int laengde): Rektangel(laengde, laengde) {} It compiles without problems. But i want to create a rectangel upon creation of a square! (rektangel == rectangel && kvadrat == square in danish)

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      You need a body for Kvadrat's destructor.

      "Love people and use things, not love things and use people." - Unknown

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      J 1 Reply Last reply
      0
      • J Jan Sommer

        I've managed to compile and run all the samples in the book so far, but all the sudden this code comes up and gives me nasty headaches. When i'm trying to compile the code below everything goes fine until the compiler tries to link it. Here's the error i get: cd /Users/summer/Documents/C++/xcodeproject/ex /Developer/usr/bin/g++-4.0 -o /Users/summer/Documents/C++/xcodeproject/ex/build/Debug/ex -L/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -F/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -filelist /Users/summer/Documents/C++/xcodeproject/ex/build/ex.build/Debug/ex.build/Objects-normal/i386/ex.LinkFileList -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk Undefined symbols: "vtable for Kvadrat", referenced from: __ZTV7Kvadrat$non_lazy_ptr in main.o ld: symbol(s) not found collect2: ld returned 1 exit status "vtable for Kvadrat", referenced from: __ZTV7Kvadrat$non_lazy_ptr in main.o ld: symbol(s) not found collect2: ld returned 1 exit status And here's the code:

        #include
        using namespace std;

        class Form
        {
        public:
        Form() {}
        virtual ~Form() {}
        virtual long HentAreal() { return -1; }
        virtual long HentOmkreds() { return -1; }
        virtual void Tegn() {}
        };

        class Rektangel : public Form
        {
        public:
        Rektangel(int laengde, int bredde):
        densLaengde(laengde), densBredde(bredde) {}
        virtual ~Rektangel() {}
        virtual long HentAreal() { return densLaengde * densBredde; }
        virtual long HentOmkreds() { return 2*densLaengde + 2*densBredde; }
        virtual int HentLaengde() { return densLaengde; }
        virtual int HentBredde() { return densBredde; }
        virtual void Tegn();
        private:
        int densBredde;
        int densLaengde;
        };

        void Rektangel::Tegn()
        {
        for (int i = 0;i < densLaengde;i++)
        {
        for (int j = 0;j < densBredde;j++)
        cout << "x";

        	cout << "\\n";
        }
        

        }

        class Kvadrat : public Rektangel
        {
        public:
        Kvadrat(int laengde);
        Kvadrat(int laengde, int bredde);
        ~Kvadrat();
        long HentOmkreds() { return 4 * HentLaengde(); }
        };

        Kvadrat::Kvadrat(int laengde):
        Rektangel(laengde, laengde)
        {}

        int main()
        {
        cout << "Do stuff";
        return 0;
        }

        When i remove Kvadrat::Kvadrat(int laengde): Rektangel(laengde, laengde) {} It compiles without problems. But i want to create a rectangel upon creation of a square! (rektangel == rectangel && kvadrat == square in danish)

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        you forgot:

        • Rektangel class default constructor (declaration & definition).
        • Kvadrat(int laengde, int bredde) constructor definition.
        • Kvadrat destructor definition

        :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        In testa che avete, signor di Ceprano?

        R 1 Reply Last reply
        0
        • D David Crow

          You need a body for Kvadrat's destructor.

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          J Offline
          J Offline
          Jan Sommer
          wrote on last edited by
          #4

          wow.. that was too simple. i feel stupid. thanks!

          1 Reply Last reply
          0
          • CPalliniC CPallini

            you forgot:

            • Rektangel class default constructor (declaration & definition).
            • Kvadrat(int laengde, int bredde) constructor definition.
            • Kvadrat destructor definition

            :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #5

            You beat me to it, you addict. :)

            Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

            CPalliniC 1 Reply Last reply
            0
            • R Rajesh R Subramanian

              You beat me to it, you addict. :)

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Rajesh R Subramanian wrote:

              You beat me to it, you addict.

              Shhhhhhhhhh, don't spread such rumors. ;)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups