New with templates!! pls help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: New with templates!! pls help

  1. #1
    Join Date
    Feb 2009
    Posts
    2

    New with templates!! pls help

    Hello. Iam new in programming and i have a problem with templates class:

    #include <iostream>

    using namespace std;

    template <class T>
    class Complex{
    T *rp,*ip; // pointers se pragmatiko kai fantastiko meros
    public:
    T real() const {return *rp;}
    T imag() const (return *ip;}
    Complex(Tr=0,Ti=0):rp(new T(r)),ip(new T(i)){}
    }

    I want to write down the destructor of the class, the copy destructor and the assignment operator. Please help!!!

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: New with templates!! pls help

    I want to write down the destructor of the class, the copy destructor and the assignment operator.
    What's the problem ? It's the same as in a class without a template.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: New with templates!! pls help

    Why are you using pointers for the real an imaginary part of the complex number? I don't see the point of that.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Feb 2009
    Posts
    2

    Lightbulb Re: New with templates!! pls help

    hello..its only for educational purposes. its not a real program. so..the destructor of that class should be like the below?

    ~Complex(){cout<<"Destructor\n"; delete rp; delete ip;}

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center