Click here to Skip to main content
       

Managed C++/CLI

 
GeneralRe: batch files PinmvpRichard MacCutchan21-Feb-13 22:36 
GeneralRe: batch files PinmemberDirquez Marquez22-Feb-13 2:58 
QuestionWhat is the CLI/C++ equivalent to the C# using statement Pinmembersujayg14-Feb-13 21:54 
AnswerRe: What is the CLI/C++ equivalent to the C# using statement PinmemberJohn Schroedl15-Feb-13 3:27 
QuestionStructures with using bit fields PinmemberAmrit Agr29-Jan-13 1:34 
AnswerRe: Structures with using bit fields PinmvpRichard MacCutchan29-Jan-13 3:38 
GeneralRe: Structures with using bit fields PinmemberAmrit Agr17-Feb-13 22:06 
Questionsopen() function in filehandling - "C" PinmemberAmrit Agr28-Jan-13 0:56 
AnswerRe: sopen() function in filehandling - "C" PinmemberJohn Schroedl28-Jan-13 3:37 
AnswerRe: sopen() function in filehandling - "C" Pinmemberramrooney27-Mar-13 7:36 
QuestionHow to call a static libray in a dll? PinmemberLongFangFang21-Jan-13 19:38 
AnswerRe: How to call a static libray in a dll? PinmvpRichard MacCutchan21-Jan-13 22:32 
Questionfrom unmanaged c++ to managed: passing int& parameter Pinmemberacastrucc19-Dec-12 4:30 
QuestionCompilation Problem [modified] Pinmembertcnm12-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 PinmvpRichard MacCutchan12-Dec-12 22:56 
Answer-Re: Compilation Problem [modified] Pinmembertcnm14-Dec-12 6:42 
GeneralRe: -Re: Compilation Problem PinmvpRichard MacCutchan14-Dec-12 21:43 
QuestionWhy c is so important? Pinmemberriceshoots10-Dec-12 4:47 
AnswerRe: Why c is so important? PinmvpRichard MacCutchan10-Dec-12 5:52 
QuestionPlease vote for C++/CLI debug visualizer support PinmemberJohn Schroedl7-Dec-12 4:25 
QuestionHow to use NTGraph3D Activex Control in Visual Studio 2010. PinmemberDhrumilS23-Nov-12 0:47 
AnswerRe: How to use NTGraph3D Activex Control in Visual Studio 2010. PinmvpRichard MacCutchan23-Nov-12 1:44 
Question'J' Character printed on empty fields on dialogs Pinmembercnuis2kool18-Nov-12 22:29 
Questionhow to get programettically a registered DLL's Version information? Pinmemberlitu kumar7-Nov-12 21:32 
AnswerRe: how to get programettically a registered DLL's Version information? PinmvpRichard MacCutchan7-Nov-12 21:43 
GeneralRe: how to get programettically a registered DLL's Version information? Pinmemberlitu kumar7-Nov-12 21:52 
GeneralRe: how to get programettically a registered DLL's Version information? PinmvpRichard MacCutchan8-Nov-12 0:04 
GeneralRe: how to get programettically a registered DLL's Version information? PinmemberH.Brydon1-Jan-13 9:46 
GeneralRe: how to get programettically a registered DLL's Version information? PinmvpRichard MacCutchan1-Jan-13 22:14 
GeneralRe: how to get programettically a registered DLL's Version information? PinmemberH.Brydon2-Jan-13 5:03 
AnswerRe: how to get programettically a registered DLL's Version information? PinmemberH.Brydon1-Jan-13 9:44 
QuestionHow to use Threadpool of I/O Completion Objects? PinmemberMichael_Tan4-Nov-12 16:10 
QuestionAny C++/CLI Experts wanted to become book author? Pinmembervivekthangaswamy4-Nov-12 16:08 
QuestionConvert 24-bit bmp capture to 8-bit capture in VC++, is it possible? Pinmemberlucky_122129-Oct-12 1:23 
AnswerRe: Convert 24-bit bmp capture to 8-bit capture in VC++, is it possible? Pinmemberjschell29-Oct-12 8:44 
QuestionCurrently i am abel to capture the 24-bit screens capturerin. Pinmemberlucky_122129-Oct-12 1:09 
QuestionCurrently I am using the log4cplu 1.0.2 version, Now i want to use the 1.1.0 version. Pinmemberlucky_122126-Oct-12 2:15 
AnswerRe: Currently I am using the log4cplu 1.0.2 version, Now i want to use the 1.1.0 version. PinmvpRichard MacCutchan26-Oct-12 3:12 
GeneralRe: Currently I am using the log4cplu 1.0.2 version, Now i want to use the 1.1.0 version. Pinmemberlucky_122127-Oct-12 0:52 
GeneralRe: Currently I am using the log4cplu 1.0.2 version, Now i want to use the 1.1.0 version. PinmvpRichard MacCutchan27-Oct-12 3:11 
Questionexceptions PinmemberEmmos201116-Oct-12 5:10 
AnswerRe: exceptions PinmvpRichard MacCutchan16-Oct-12 8:22 
Questionc++/cli define new explicit implementation of a sealed method PinmemberMarius Bancila10-Oct-12 23:21 
AnswerRe: c++/cli define new explicit implementation of a sealed method PinmemberJohn Schroedl11-Oct-12 3:19 
GeneralRe: c++/cli define new explicit implementation of a sealed method PinmemberJohn Schroedl11-Oct-12 3:29 
GeneralRe: c++/cli define new explicit implementation of a sealed method PinmemberMarius Bancila11-Oct-12 10:12 
GeneralRe: c++/cli define new explicit implementation of a sealed method PinmemberJohn Schroedl12-Oct-12 2:29 
GeneralRe: c++/cli define new explicit implementation of a sealed method PinmemberMarius Bancila11-Oct-12 21:35 
GeneralRe: c++/cli define new explicit implementation of a sealed method PinmemberJohn Schroedl12-Oct-12 2:34 
GeneralRe: c++/cli define new explicit implementation of a sealed method PinmemberJohn Schroedl12-Oct-12 2:38 

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

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


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 18 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid