Click here to Skip to main content
15,910,981 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Function Taking Generic Vector? Pin
Nishad S1-Feb-09 19:25
Nishad S1-Feb-09 19:25 
QuestionFolder Copy Pin
Davitor1-Feb-09 17:30
Davitor1-Feb-09 17:30 
AnswerRe: Folder Copy Pin
«_Superman_»1-Feb-09 17:58
professional«_Superman_»1-Feb-09 17:58 
GeneralRe: Folder Copy Pin
Davitor1-Feb-09 18:09
Davitor1-Feb-09 18:09 
QuestionRe: Folder Copy Pin
David Crow2-Feb-09 5:52
David Crow2-Feb-09 5:52 
AnswerRe: Folder Copy Pin
«_Superman_»1-Feb-09 18:12
professional«_Superman_»1-Feb-09 18:12 
AnswerRe: Folder Copy Pin
ATM@CodeProject1-Feb-09 18:52
ATM@CodeProject1-Feb-09 18:52 
QuestionTemplate Class: Problem with Header file Pin
gvanto1-Feb-09 13:53
gvanto1-Feb-09 13:53 
I'm having a problem with getting a template class's code split into a header and source file. The following three files below simply refuse to compile, error (using Eclipse Ganymede on Kubuntu Hardy Heron) below.

W.r.t. the 3 files below, when I include the GenArray.cpp 's code INTO the GenArray.h file or include both GenArray.h and .cpp 's contents into the TestDemo, it works
just fine! Any help on how to use this header file correctly would be greatly appreciated !

gvanto

[CODE]
Compiler output:

make all
Building file: ../src/GenArray.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/GenArray.d" -MT"src/GenArray.d" -o"src/GenArray.o" "../src/GenArray.cpp"
Finished building: ../src/GenArray.cpp

Building file: ../src/TestDemo.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/TestDemo.d" -MT"src/TestDemo.d" -o"src/TestDemo.o" "../src/TestDemo.cpp"
Finished building: ../src/TestDemo.cpp

Building target: STLTest
Invoking: GCC C++ Linker
g++ -o"STLTest" ./src/GenArray.o ./src/TemplateClassDemo.o ./src/TemplateFunctionDemo.o ./src/TestDemo.o ./src/VirtualClassDemo.o ./src/rectangle.o
./src/TestDemo.o: In function `main':
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:21: undefined reference to `GenArray<int, 10>::operator[](int)'
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:22: undefined reference to `GenArray<int, 10>::operator[](int)'
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:25: undefined reference to `GenArray<double, 15>::operator[](int)'
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:26: undefined reference to `GenArray<double, 15>::operator[](int)'
collect2: ld returned 1 exit status

[/CODE]




[CODE]
/*
* TestDemo.cpp
*
* Created on: 1/02/2009
* Author: pacific
*/

#include <iostream>
#include <cstdlib>
#include "GenArray.h"

using namespace std;

int main() {

GenArray<int, 10> intob; //int array of size 10
GenArray<double, 15> doubleob; //double array of size 15

int i;
cout << "Integer array: ";
for(i=0; i<10; i++) intob[i] = i;
for(i=0; i<10; i++) cout << intob[i] << " ";
cout << '\n';
cout << "Double array: ";
for(i=0; i<15; i++) doubleob[i] = (double) i/3;
for(i=0; i<15; i++) cout << doubleob[i] << " ";

return 0;
}
[/CODE]

[CODE]
/*
* GenArray.h
*
* Created on: 1/02/2009
* Author: pacific
*/

//A Generic Safe-Array

#include <iostream>
#include <cstdlib>
using namespace std;

template <class AType, int size> class GenArray {
AType a[size]; //length of array is passed in size

public:
GenArray() {
register int i;
for(i = 0; i < size;i++) {
a[i] = i;
}
}
AType &operator[](int i);

};
[/CODE]

[CODE]
/**
* Source for GenArray.h
*/

#include "GenArray.h" //this already includes iostream and stuff


//Provide range-checking for GenArray
template <class AType, int size> AType &GenArray<AType, size>::operator[] (int i) {
if(i<0 || i> size-1) {
cout << "\nIndex value of ";
cout << i << " is out-of-bounds.\n";
exit(1);
}
return a[i];
}

[/CODE]

Get A job in Australia now, Free!
http://www.webcv.com.au
AnswerRe: Template Class: Problem with Header file Pin
«_Superman_»1-Feb-09 17:20
professional«_Superman_»1-Feb-09 17:20 
GeneralRe: Template Class: Problem with Header file Pin
gvanto1-Feb-09 17:52
gvanto1-Feb-09 17:52 
QuestionIs assignment to int atomic Pin
Dudi Avramov1-Feb-09 9:44
Dudi Avramov1-Feb-09 9:44 
AnswerRe: Is assignment to int atomic Pin
Alexander M.,1-Feb-09 9:49
Alexander M.,1-Feb-09 9:49 
QuestionRe: Is assignment to int atomic Pin
CPallini1-Feb-09 10:17
mveCPallini1-Feb-09 10:17 
AnswerRe: Is assignment to int atomic Pin
Joe Woodbury1-Feb-09 16:53
professionalJoe Woodbury1-Feb-09 16:53 
GeneralRe: Is assignment to int atomic Pin
Joe Woodbury1-Feb-09 16:52
professionalJoe Woodbury1-Feb-09 16:52 
AnswerRe: Is assignment to int atomic Pin
Randor 1-Feb-09 10:48
professional Randor 1-Feb-09 10:48 
GeneralRe: Is assignment to int atomic Pin
Dudi Avramov1-Feb-09 21:26
Dudi Avramov1-Feb-09 21:26 
GeneralRe: Is assignment to int atomic Pin
Stuart Dootson1-Feb-09 22:13
professionalStuart Dootson1-Feb-09 22:13 
Questiondecoding pdf format into device Pin
Horizzzon1-Feb-09 8:18
Horizzzon1-Feb-09 8:18 
AnswerRe: decoding pdf format into device Pin
CPallini1-Feb-09 10:23
mveCPallini1-Feb-09 10:23 
GeneralRe: decoding pdf format into device Pin
Horizzzon1-Feb-09 10:43
Horizzzon1-Feb-09 10:43 
QuestionStrncmp and GetwindowText problem Pin
keret1-Feb-09 6:18
keret1-Feb-09 6:18 
AnswerRe: Strncmp and GetwindowText problem Pin
Stephen Hewitt1-Feb-09 6:49
Stephen Hewitt1-Feb-09 6:49 
AnswerRe: Strncmp and GetwindowText problem Pin
Cedric Moonen1-Feb-09 7:31
Cedric Moonen1-Feb-09 7:31 
GeneralRe: Strncmp and GetwindowText problem Pin
keret1-Feb-09 8:38
keret1-Feb-09 8:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.