Click here to Skip to main content
15,885,985 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Structures with using bit fields Pin
Amrit Agr17-Feb-13 22:06
Amrit Agr17-Feb-13 22:06 
Questionsopen() function in filehandling - "C" Pin
Amrit Agr28-Jan-13 0:56
Amrit Agr28-Jan-13 0:56 
AnswerRe: sopen() function in filehandling - "C" Pin
John Schroedl28-Jan-13 3:37
professionalJohn Schroedl28-Jan-13 3:37 
AnswerRe: sopen() function in filehandling - "C" Pin
ramrooney27-Mar-13 7:36
ramrooney27-Mar-13 7:36 
QuestionHow to call a static libray in a dll? Pin
LongFangFang21-Jan-13 19:38
LongFangFang21-Jan-13 19:38 
AnswerRe: How to call a static libray in a dll? Pin
Richard MacCutchan21-Jan-13 22:32
mveRichard MacCutchan21-Jan-13 22:32 
Questionfrom unmanaged c++ to managed: passing int& parameter Pin
acastrucc19-Dec-12 4:30
acastrucc19-Dec-12 4:30 
QuestionCompilation Problem Pin
tcnm12-Dec-12 9:18
tcnm12-Dec-12 9:18 
Four programs (listings 19.4, 19.5, 19.6 and 19.7) in the book
"Teach Yourself C++ in 21 Days" by Jesse Liberty and Bradley Jones
do not compile. The first of these programs is as follows:

//Listing 19.4 Using Operator ostream
#include <iostream>
using namespace std;

const int DefaultSize = 10;

class Animal
{
public:
Animal(int);
Animal();
~Animal() {}
int GetWeight() const { return itsWeight; }
void Display() const { cout << itsWeight; }
private:
int itsWeight;
};

Animal::Animal(int weight):
itsWeight(weight)
{}

Animal::Animal():
itsWeight(0)
{}

template <class T> // declare the template and the parameter
class Array // the class being parameterized
{
public:
// constructors
Array(int itsSize = DefaultSize);
Array(const Array &rhs);
~Array() { delete [] pType; }

// operators
Array& operator=(const Array&);
T& operator[](int offSet) { return pType[offSet]; }
const T& operator[](int offSet) const
{ return pType[offSet]; }
// accessors
int GetSize() const { return itsSize; }

// template <class T>
friend ostream& operator<< (ostream&, Array<T>&);
private:
T *pType;
int itsSize;
};

template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
for (int i = 0; i < theArray.itsSize; i++)
{
output << "[" << i << "] " << theArray[i] << endl;
}
return output;
}


// implementations follow...

// implement the Constructor
template <class T>
Array<T>::Array(int size):
itsSize(size)
{
pType = new T[size];
for (int i = 0; i < size; i++)
pType[i] = 0;
}

// copy constructor
template <class T>
Array<T>::Array(const Array &rhs)
{
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i = 0; i < itsSize; i++)
pType[i] = rhs[i];
}

// operator=
template <class T>
Array<T>& Array<T>::operator=(const Array &rhs)
{
if (this == &rhs)
return *this;
delete [] pType;
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i = 0; i < itsSize; i++)
pType[i] = rhs[i];
return *this;
}

int main()
{
bool Stop = false; // flag for looping
int offset, value;<pre lang="c++"></pre>
Array<int> theArray;

while (Stop == false)
{
cout << "Enter an offset (0-9) ";
cout << "and a value. (-1 to stop): ";
cin >> offset >> value;

if (offset < 0)
break;

if (offset > 9)
{
cout << "***Please use values between 0 and 9.***\n";
continue;
}

theArray[offset] = value;
}

cout << endl << "Here's the entire array:" << endl;
cout << theArray << endl;
return 0;
}

Attempting to compile this program on Linux with g++ produces the
following message:

g++ -fpermissive list1904.cpp -o List19.4
list1904.cpp:45:52: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, Array<T>&)’ declares a non-template function [-Wnon-template-friend]
list1904.cpp:45:52: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)
/tmp/ccgXupn5.o: In function `main':
list1904.cppFrown | :( text+0x102): undefined reference to `operator<<(std::ostream&, Array<int>&)'
collect2: error: ld returned 1 exit status
make: *** [List19.4] Error 1

I would very much appreciate any help in resolving this problem.
Thank you very much,

tim_mann

tcnm

-- modified 14-Dec-12 16:09pm.
QuestionRe: Compilation Problem Pin
Richard MacCutchan12-Dec-12 22:56
mveRichard MacCutchan12-Dec-12 22:56 
Answer-Re: Compilation Problem Pin
tcnm14-Dec-12 6:42
tcnm14-Dec-12 6:42 
GeneralRe: -Re: Compilation Problem Pin
Richard MacCutchan14-Dec-12 21:43
mveRichard MacCutchan14-Dec-12 21:43 
QuestionWhy c is so important? Pin
riceshoots10-Dec-12 4:47
riceshoots10-Dec-12 4:47 
AnswerRe: Why c is so important? Pin
Richard MacCutchan10-Dec-12 5:52
mveRichard MacCutchan10-Dec-12 5:52 
QuestionPlease vote for C++/CLI debug visualizer support Pin
John Schroedl7-Dec-12 4:25
professionalJohn Schroedl7-Dec-12 4:25 
QuestionHow to use NTGraph3D Activex Control in Visual Studio 2010. Pin
DhrumilS23-Nov-12 0:47
DhrumilS23-Nov-12 0:47 
AnswerRe: How to use NTGraph3D Activex Control in Visual Studio 2010. Pin
Richard MacCutchan23-Nov-12 1:44
mveRichard MacCutchan23-Nov-12 1:44 
Question'J' Character printed on empty fields on dialogs Pin
cnuis2kool18-Nov-12 22:29
cnuis2kool18-Nov-12 22:29 
Questionhow to get programettically a registered DLL's Version information? Pin
litu kumar7-Nov-12 21:32
litu kumar7-Nov-12 21:32 
AnswerRe: how to get programettically a registered DLL's Version information? Pin
Richard MacCutchan7-Nov-12 21:43
mveRichard MacCutchan7-Nov-12 21:43 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
litu kumar7-Nov-12 21:52
litu kumar7-Nov-12 21:52 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
Richard MacCutchan8-Nov-12 0:04
mveRichard MacCutchan8-Nov-12 0:04 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
H.Brydon1-Jan-13 9:46
professionalH.Brydon1-Jan-13 9:46 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
Richard MacCutchan1-Jan-13 22:14
mveRichard MacCutchan1-Jan-13 22:14 
GeneralRe: how to get programettically a registered DLL's Version information? Pin
H.Brydon2-Jan-13 5:03
professionalH.Brydon2-Jan-13 5:03 
AnswerRe: how to get programettically a registered DLL's Version information? Pin
H.Brydon1-Jan-13 9:44
professionalH.Brydon1-Jan-13 9:44 

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.