On Managed C++


I just got forwarded a list of resources on MC++… I
thought I’d file them away for future reference.



· MSDN documentation: href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vcconmcoverview.asp?frame=true"> face=Verdana color=#0000ff
size=2>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vcconmcoverview.asp?frame=true

size=2>

· C++ with Managed Extensions on GotDotNet:
face=Verdana color=#0000ff
size=2>http://www.gotdotnet.com/team/upgrade/c++.aspx

size=2>

· MC++ resources at The Code Project:
color=#0000ff
size=2>http://www.codeproject.com/managedcpp/


size=2> 


 

Comments (2)

  1. sebastian says:

    hello,

    in this Code i have Probleme ,i don t know which the probleme in (operator *)

    thinks for your help

    #include <iostream>

    #include <cmath>

    #include "RGB.h"

    #include <iterator>

    #include <algorithm>

    #include<string.h>

    #include <vector>

    #include <limits>

    using namespace std;

    template < class T1,class T2> struct PromotionTraits {typedef T1 ResultType;};

    //////////////////////////////////////////////////////////////////////////////////////////

    template<> struct PromotionTraits<int, char> {typedef int ResultType; };

    template<> struct PromotionTraits<int, unsigned char> {typedef int ResultType; };

    template<> struct PromotionTraits<int, float> {typedef float ResultType; };

    template<> struct PromotionTraits<int, double> {typedef double ResultType; };

    template<> struct PromotionTraits<int, long > {typedef long ResultType; };

    template<> struct PromotionTraits<int, unsigned long> {typedef unsigned long ResultType; };

    ///////////////////////////////////////////////////////////////////////////////////

    template<class T1, class T2>

    struct PromotionTraits<RGB<T1>, T2> { typedef RGB<typename PromotionTraits<T1, T2>::ResultType> ResultType; };

    template<class T1, class T2>

    struct PromotionTraits<T1, RGB<T2> >

    { typedef RGB<typename PromotionTraits<T1, T2>::ResultType> ResultType; };

    /////////////////////////////////////////////////////

    template<>

    struct PromotionTraits<RGB<double>, double>

    { typedef RGB<typename PromotionTraits<double, double>::ResultType> ResultType; };

    ///////////////////////////////////////////////////////////////////////////////

    template<class T>

    class RGB

    {

    public:

    T red;

    T green;

    T blue;

    RGB() : red(0), green(0), blue(0) {}; //default constructor

    RGB(T red_, T green_, T blue_) //Constructor

    { red= red_;

    green = green_;

    blue = blue_;

    }

    RGB(const RGB& pix) //Copy Constructor

    {

    this->red = 0;

    this->green = 0;

    this->blue = 0;

    this->red = pix.red;

    this->green = pix.green;

    this->blue = pix.blue;

    }

    RGB<T>& operator=( const RGB<T>& pix){ //Zuweisung Operator

    if(this != &pix)

    this->red = pix.red;

    this->green = pix.green;

    this->blue = pix.blue;

    return *this;

    }

    RGB<T> operator+(const RGB<T>& colorValue) const {

    RGB<T> result;

    result.red = this->red + colorValue.red;

    result.green = this->green + colorValue.green;

    result.red = this->blue + colorValue.blue;

    return result;

    }

    RGB<T> operator+(const T& value) const {

    RGB<T> result;

    result.red = this->red + value;

    result.green = this->green + value;

    result.red = this->blue + value;

    return result;

    }

    };

    ///////////////////////////////////////////////////////////////////////////////

    template<class T>

    class Image

    {

    //private:

    public:

    int zeilen;

    int spalten;

    T *daten;

    typedef T value_type;

    typedef T* iterator;

    typedef const T* const_iterator;

    typedef std::reverse_iterator<iterator> reverse_iterator;

    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

    Image() : daten(0) {}

    Image(int zeilen_, int spalten_)

    {

    zeilen = zeilen_;

    spalten = spalten_;

    daten = new T[zeilen*spalten];

    }

    /*

    Image(int zeilen_, int spalten_, T wert)

    {

    zeilen = zeilen_;

    spalten = spalten_;

    daten = new T[zeilen*spalten];

    Image<T>::iterator begin;

    Image<T>::iterator end;

    Image<T>::iterator it;

    begin = this->begin();

    end = this->end();

    for ( it = begin; it!=end; it++){

    *it= wert;

    }

    }*/

    //===========================================================

    Image(int zeilen_, int spalten_, RGB<T>& rgb)

    {

    zeilen = zeilen_;

    spalten = spalten_;

    daten = new RGB<T>[zeilen*spalten];

    Image<RGB<T> >::iterator begin;

    Image<RGB<T> >::iterator end;

    Image<RGB<T> >::iterator it;

    begin = this->begin();

    end = this->end();

    for ( it = begin; it!=end; it++){

    it->green = rgb.green;

    it->red = rgb.red;

    it->blue = rgb.blue;

    }

    }

    //==========================================================

    Image(const Image& a)

    {

    daten = 0;

    *this = a;

    }

    ~Image()

    {

    delete[] daten;

    }

    Image<T>& operator=(const Image<T>& a)

    {

    /*if (this->zeilen * this->spalten != a.zeilen*a.spalten){

    delete[] daten;

    daten = 0;

    }*/

    this->zeilen = a.zeilen;

    this->spalten = a.spalten;

    if (daten == 0) {

    daten = new T[zeilen*spalten];

    }

    Image<T>::iterator iterA;

    Image<T>::iterator iterB;

    Image<T>::iterator end;

    iterA = a.begin();

    iterB = this->begin();

    end = this->end();

    while (!(iterB == end)){

    iterB->red = iterA->red;

    iterB->green = iterA->green;

    iterB->blue = iterA->blue;

    iterA++;

    iterB++;

    }

    return *this;

    }

    /////////////////////////////////////////////////////////////////

    T& operator[](int i) const{

    return daten[i];

    }

    T& operator() (int zeile, int spalte)const {

    return daten[zeile + zeilen*spalte];

    }

    iterator begin() const {

    return daten;

    }

    iterator end() const{

    return &daten[zeilen*spalten];

    }

    reverse_iterator rbegin()const {return reverse_iterator(end());}

    reverse_iterator rend()const {return reverse_iterator(begin());}

    ///////////////////////////////////////////////////////////////////////

    template <typename T1,typename T2> inline

    Image<typename PromotionTraits<RGB<T1>, T2 >::ResultType >

    operator *(const Image<RGB<T1> >& a, T2 m){

    typedef typename PromotionTraits<RGB<T1>, T2 >::ResultType ResultType;

    Image<RGB<ResultType> > c(a.zeilen, a.spalten);

    //Image<ResultType> c(a.zeilen, a.spalten);

    typename Image<RGB<T1> >::iterator iterA, end;

    //Image<RGB<T2> >::iterator iterB;

    typename Image<RGB<ResultType> >::iterator iterC;

    //Image<T1>::iterator ;

    iterA = a.begin();

    //iterB = b.begin();

    end = a.end(); //?????????

    //??????????

    while (iterA != end){

    //RGB<ResultType> pixC;

    iterC->red = iterA->red + m ;

    iterC->green = iterA->green + m ;

    iterC->blue = iterA->blue + m ;

    iterC++;

    iterA++;

    //iterB++;

    }

    return c;

    }

    /////////////////////////////////////

    void main(){

    RGB<int> rgbA;

    rgbA.red = 10;

    rgbA.green = 10;

    rgbA.blue = 10;

    Image<RGB<int> >rgbImageA(10, 10,rgbA);

    Image<RGB<int> >rgbImageB(10, 10,rgbA);

    Image<RGB<int> >rgbImageC;

    rgbImageC = rgbImageA * 3;

    }

Skip to main content