c++ - Symbol undefined error
- placr (61/61) Oct 22 2010 Hello,
Hello, I am getting a "symbol undefined" error when compiling the below code as follows: dmc -Ic:\dm\stlport\stlport -cpp Orange.cpp dmc -Ic:\dm\stlport\stlport -cpp main.cpp All files (.cpp and .h) are in the same directory. Any clues? Many thanks. placr ------------ Orange.cpp ------------- #include "Orange.h" string Orange::getName() { return (name_); } ------------------------------------- --------------- Orange.h ------------ #ifndef ORANGE_H__ #define ORANGE_H__ #include <string> using namespace std; class Orange { public: Orange() : name_("") {} Orange(string& p) : name_(p) {} string getName(); private: string name_; }; #endif ------------ main.cpp --------------- #include <iostream> #include <tchar.h> #include <string> #include "Orange.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string orange_name = "Green Orange"; Orange(); Orange oran(orange_name); cout << oran.getName() << endl; return 0; } // end main ---------------- Error message ------------- "Compiling main.cpp..." link Orange,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 8.00.5 Copyright (C) Digital Mars 1989-2009 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 134: No Start Address link main,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 8.00.5 Copyright (C) Digital Mars 1989-2009 All rights reserved. http://www.digitalmars.com/ctg/optlink.html main.obj(main) Error 42: Symbol Undefined ?getName Orange QAE?AV?$basic_string std DV?$char_traits std D 1 V?$allocator std D 1 std (basic_string<>::d: :DV?$char_traits::std::D::Orange syscall Orange::getName(allocator<>::d::D::Orange )) --- errorlevel 1
Oct 22 2010