Announcement

Collapse
No announcement yet.

Probleme beim Erstellen eines Arrays von Objekten

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Probleme beim Erstellen eines Arrays von Objekten

    hi!
    ich schreibe grad an einer win-forms anwendung (c++/cli) und bin da auf ein mir unerklärliches problem gestoßen:

    ich habe ein objekt "Botschaft" angelegt und möche ein array erstellen, in dem mehrere "Botschaften" abgelegt werden sollen.

    hab mich also noch ma sicherheitshalber bei microsoft belesen, was das erstellen von arrays in managed c++ angeht und bin auf diese seite gestoßen

    http://msdn.microsoft.com/de-de/libr...=vs.80%29.aspx

    mit folgendem beispiel, welches eiglich genau das wieder gibt, was ich machen möchte:

    Code:
    // clr_array.cpp
    // compile with: /clr
    ref class MyClass {};
    int main() {
       array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);
    }
    dem beispiel entsprechend habe ich das ganze auch bei mir umgesetzt:

    Form1.h
    Code:
    #pragma once
    #include "Botschaft.h"
    #include "Signal.h"
    
    
    namespace Eingabemodul_02 {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	#define MAX_BO = 50
    	#define MAX_SG = 150
    
    	/// <summary>
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the
    	///          'Resource File Name' property for the managed resource compiler tool
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    
    
    
    
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    			tempNodeName = "";
    			BOnodeAnz = 0;
    			SGnodeAnz = 0;
    			array< Botschaft^ >^ arr1 = gcnew array< Botschaft^ >(MAX_BO);
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::TreeView^  treeView1;
    	protected: 
    	private: Botschaft^ tempBo;
    	private: Signal^ tempSg;
    	private: String^ tempNodeName;
    	private: int BOnodeAnz;
    	private: int SGnodeAnz;
    [...]

    nun bekomme ich aber seltsamer weise immer bei der zeile
    Code:
    			array< Botschaft^ >^ arr1 = gcnew array< Botschaft^ >(MAX_BO);
    folgenden fehler:

    \Form1.h(43) : error C2059: syntax error : '='
    was läuft da falsch, bzw wo ist mein denkfehler?

    danke schon mal
    Zuletzt editiert von Seradir; 21.04.2011, 09:45.

  • #2
    Compiler option: /clr

    gesetzt?
    Christian

    Comment


    • #3
      Originally posted by Christian Marquardt View Post
      Compiler option: /clr

      gesetzt?
      dachte eiglich schon...



      hatte das ma iwo im inet so beschrieben gesehen und bisher keene probleme damit...

      Comment


      • #4
        Habe zwar kein VC, aber das sind Debugger-Optionen?
        Christian

        Comment


        • #5
          jop, arbeite ja im mom auch im debug-modus (und nich im release)

          Comment


          • #6
            kann mir da noch jemand weiterhelfen?

            Comment


            • #7
              Originally posted by Christian Marquardt View Post
              Compiler option: /clr

              gesetzt?
              also ja, hab ich definitiv gesetzt.
              hab zwar vorher an der falschen stelle geguggt, aber jetzt bin ich mir sicher dass es gesetzt is.
              (bei Configuration properties -> General is eingestellt "Common Language Runtime Support (/clr)")

              Comment


              • #8
                fehler gefunden...
                arrays von objekten können anscheinend nur eine größe von 32 haben...

                Comment


                • #9
                  ?? Steht aber so nirgends drin...Auch die Beispiele sind anders
                  Christian

                  Comment


                  • #10
                    hm, ne... an ner grße von >32 lags doch nich... hab heute noch ma andere werte ausprobiert und es hat funktioniert
                    dann liegts wohl an der definierten konstante MAX_BO
                    wenn ich direkt ne zahl eingebe gehts, wenn ich die konstante reinpacke nich :-/ das verstehe wer will
                    Zuletzt editiert von Seradir; 21.04.2011, 09:50.

                    Comment

                    Working...
                    X