c++ - undefined symbols for architecture x86_64: "Shape::get_area()", referenced from: votable for shape in shape.o -


hi i'm pretty sure issue stupid cannot figure out life of me. have homework assignment meant reinforce have learned polymorphism in class (this c++ way). basis of program class called shape parent circle, triangle , rectangle.

im getting linker error pure virtual method get_area() meant defined in child classes. can't life of me figure out why won't compile, haven't made main method make use of yet , prototype method shouldn't link right?

anyway here code shape.h file:

#ifndef assign8_shape_h #define assign8_shape_h  #include <iostream> #include <stdio.h> #include <string>  using namespace::std;  class shape{  private:     string color;  public:     shape(const string& n_color);     virtual ~shape ();     void print();     virtual double get_area() = 0;  };  #endif 

and here shape.cpp file:

#include <stdio.h> #include <string> #include "shape.h"  using namespace::std;  shape::shape(const string& n_color) {     color = n_color; }  shape::~shape (){  }  void shape::print() {     cout << color; } 

and here example of how problematic method overwritten in circle.h:

#ifndef __assign8__circle__ #define __assign8__circle__  #include <stdio.h> #include <string> #include "shape.h"  using namespace::std;   class circle : public shape {  public:     circle(const string& n_color, int n_radius);     void print();     double get_area();    private:     int radius;  }; 

and in circle.cpp:

#include "circle.h"   using namespace::std;  circle::circle(const string& n_color, int n_radius) : shape(n_color) {     radius = n_radius; }  void circle::print(){     shape::print();     cout  << ", radius " << radius << " area " << get_area(); }  double circle::get_area() {     double pi = 3.14159265359;      return pi * (radius * radius); } 

and here full body of error:

ld /users/username/library/developer/xcode/deriveddata/csci241-dhkihmradodwdkerbhwjkshakexl/build/products/debug/assign8 normal x86_64     cd /users/username/documents/niu/csci241/assign8     export macosx_deployment_target=10.9     /applications/utilities/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /applications/utilities/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.10.sdk -l/users/username/library/developer/xcode/deriveddata/csci241-dhkihmradodwdkerbhwjkshakexl/build/products/debug -f/users/username/library/developer/xcode/deriveddata/csci241-dhkihmradodwdkerbhwjkshakexl/build/products/debug -filelist /users/username/library/developer/xcode/deriveddata/csci241-dhkihmradodwdkerbhwjkshakexl/build/intermediates/assign8.build/debug/assign8.build/objects-normal/x86_64/assign8.linkfilelist -mmacosx-version-min=10.9 -stdlib=libc++ -xlinker -dependency_info -xlinker /users/username/library/developer/xcode/deriveddata/csci241-dhkihmradodwdkerbhwjkshakexl/build/intermediates/assign8.build/debug/assign8.build/objects-normal/x86_64/assign8_dependency_info.dat -o /users/username/library/developer/xcode/deriveddata/csci241-dhkihmradodwdkerbhwjkshakexl/build/products/debug/assign8  undefined symbols architecture x86_64:   "shape::get_area()", referenced from:       vtable shape in shape.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) 

your code compiles without problems on ubuntu g++ version 4.8.2:

$ g++ -o c circle.cpp shape.cpp $ ./c area=28.274334  int main() {    circle c ("white", 3);   printf("area=%lf\n", c.get_area());   return 0; } 

you omitted #endif @ end of circle.h, , shape.h should named shape.h. how compiling , linking code? not having pieces of program in process?


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -