- Admin
- #1
I am using Visual Studio 2008 Professional on Windows and G++ on Unix. My program compiles in both of them. I have the following class definition in my header file:
template
class SearchableList: public list
{
public:
*** int count(_Ty needle, int start = 0)
*** bool inList(_Ty needle, int start = 0)
*** void cycle()
*** void rcycle()
}
I wrote the SearchableList class to extend the C++ list class because I needed more functionality than it provided and I wanted to familiarize myself with the C++ list class. This is the first time I have ever used inheritance, so it took a few hours of googling stuff and trial and error to create external member functions for the class that would compile.
I have the member functions in a searchableList.cpp file, which has the following code:
#include "header.h"
template
int SearchableList::count(_Ty needle, int start)
{
*** int answer = 0, i
*** //Make sure that starting variable is within range of list
*** start %= this->size()
*** for ( i = 0 i < start i++ )
*** {
*** *** this->cycle()
*** }
*** for (* i < this->size() i++ )
*** {
*** *** // Check to see if we have a match
*** *** if (this->front() == needle) answer++
*** *** // Cycle List
*** *** this->cycle()
*** }
*** return answer
}
template
bool SearchableList::inList(_Ty needle, int start)
{
*** return (this->count(needle, start) > 0)
}
template
void SearchableList::cycle()
{
*** this->push_back(this->front())
*** this->pop_front()
***
}
template
void SearchableList::rcycle()
{
*** this->push_front(this->back())
*** this->pop_back()
***
}
My program relies on (most) of this classes' member functions. It compiles without a problem, whenever the linker is run, I get a linker error. I have been using workarounds that rely on the parent classes' methods, but it is getting to the point where I cannot do this anymore and I must to be able to use this classes' member functions. Here is an example of a linker error that comes from using one of the member functions:
1>recordArray.obj : error LNK2019: unresolved external symbol "public: bool __thiscall SearchableList::inList(int,int)" (?inList@?$SearchableList@HV?$allocator@H@std@@@@QAE_NHH@Z) referenced in function "public: class SearchableList __thiscall RecordArray::getSemesterList(class std::basic_string const &)const " (?getSemesterList@RecordArray@@QBE?AV?$SearchableList@V?$
basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@
@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$
allocator@D@2@@std@@@2@@@ABV?$basic_string@DU?$char_traits
@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Documents and Settings\Richard\My Documents\Visual Studio 2008\Projects\hw4\Debug\hw4.exe : fatal error LNK1120: 1 unresolved externals
Note: I added a few newlines to the above text to make it fit in channel9's post area.
I also get a similar linker error from G++ on Unix:
g++ -o hw4.out main.o read.o record.o recordArray.o recordList.o searchableList.o
Undefined********************** first referenced
*symbol**************************** in file
SearchableList::inList(int, int)recordArray.o
ld: fatal: Symbol referencing errors. No output written to hw4.out
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `project'
Would someone please tell me what is wrong?
More...
View All Our Microsoft Related Feeds
template
class SearchableList: public list
{
public:
*** int count(_Ty needle, int start = 0)
*** bool inList(_Ty needle, int start = 0)
*** void cycle()
*** void rcycle()
}
I wrote the SearchableList class to extend the C++ list class because I needed more functionality than it provided and I wanted to familiarize myself with the C++ list class. This is the first time I have ever used inheritance, so it took a few hours of googling stuff and trial and error to create external member functions for the class that would compile.
I have the member functions in a searchableList.cpp file, which has the following code:
#include "header.h"
template
int SearchableList::count(_Ty needle, int start)
{
*** int answer = 0, i
*** //Make sure that starting variable is within range of list
*** start %= this->size()
*** for ( i = 0 i < start i++ )
*** {
*** *** this->cycle()
*** }
*** for (* i < this->size() i++ )
*** {
*** *** // Check to see if we have a match
*** *** if (this->front() == needle) answer++
*** *** // Cycle List
*** *** this->cycle()
*** }
*** return answer
}
template
bool SearchableList::inList(_Ty needle, int start)
{
*** return (this->count(needle, start) > 0)
}
template
void SearchableList::cycle()
{
*** this->push_back(this->front())
*** this->pop_front()
***
}
template
void SearchableList::rcycle()
{
*** this->push_front(this->back())
*** this->pop_back()
***
}
My program relies on (most) of this classes' member functions. It compiles without a problem, whenever the linker is run, I get a linker error. I have been using workarounds that rely on the parent classes' methods, but it is getting to the point where I cannot do this anymore and I must to be able to use this classes' member functions. Here is an example of a linker error that comes from using one of the member functions:
1>recordArray.obj : error LNK2019: unresolved external symbol "public: bool __thiscall SearchableList::inList(int,int)" (?inList@?$SearchableList@HV?$allocator@H@std@@@@QAE_NHH@Z) referenced in function "public: class SearchableList __thiscall RecordArray::getSemesterList(class std::basic_string const &)const " (?getSemesterList@RecordArray@@QBE?AV?$SearchableList@V?$
basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@
@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$
allocator@D@2@@std@@@2@@@ABV?$basic_string@DU?$char_traits
@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Documents and Settings\Richard\My Documents\Visual Studio 2008\Projects\hw4\Debug\hw4.exe : fatal error LNK1120: 1 unresolved externals
Note: I added a few newlines to the above text to make it fit in channel9's post area.
I also get a similar linker error from G++ on Unix:
g++ -o hw4.out main.o read.o record.o recordArray.o recordList.o searchableList.o
Undefined********************** first referenced
*symbol**************************** in file
SearchableList::inList(int, int)recordArray.o
ld: fatal: Symbol referencing errors. No output written to hw4.out
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `project'
Would someone please tell me what is wrong?
More...
View All Our Microsoft Related Feeds