Problem z nazwą przestrzeni System::Globalization


(przemekKK) #1

Dlaczego kompilator zgłasza błąd:

1>c:\users\przemek\documents\visual studio 2008\projects\numberstyles\numberstyles\numberstyles\Form1.h(115) : error C2872: 'NumberStyles' : ambiguous symbol

1> could be 'NumberStyles'

1> or 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Globalization::NumberStyles'

1>c:\users\przemek\documents\visual studio 2008\projects\numberstyles\numberstyles\numberstyles\Form1.h(115) : error C2039: 'HexNumber' : is not a member of 'NumberStyles'

1>c:\users\przemek\documents\visual studio 2008\projects\numberstyles\numberstyles\numberstyles\Form1.h(115) : error C2065: 'HexNumber' : undeclared identifier

w kodzie:

liczba_single=System::Int32::Parse(textBox1->Text, NumberStyles::HexNumber);

Mimo że dodałem using namespace System::Globalization;. Natomias kod:

liczba_single=System::Int32::Parse(textBox1->Text, System::Globalization::NumberStyles::HexNumber);

Kompiluje się bez problemu. Co on nie widzi przestrzeni nazw? A oto przykład z pomocy:

int stringValue = Int32::Parse(numberString, NumberStyles::HexNumber);

jest tylko NumberStyles::HexNumber !!


(somekind) #2

Po pierwsze nie napisałeś o jaki język chodzi, trzeba się domyślać.

Po drugie, u mnie działa. Pokaż więcej kodu i opisz szczegółowo okoliczności wystąpienia błędu.


(przemekKK) #3

Język to C++/CLI

#pragma once



namespace NumberStyles {


	using namespace System;

	using namespace System::ComponentModel;

	using namespace System::Collections;

	using namespace System::Windows::Forms;

	using namespace System::Data;

	using namespace System::Drawing;

	using namespace System::Globalization;





	/// 

	/// 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.

	/// 

	public ref class Form1 : public System::Windows::Forms::Form

	{

	public:

		Form1(void)

		{

			InitializeComponent();

			//

			//TODO: Add the constructor code here

			//

		}


	protected:

		/// 

		/// Clean up any resources being used.

		/// 

		~Form1()

		{

			if (components)

			{

				delete components;

			}

		}


	protected: 

	private: System::Windows::Forms::Label^ label1;

	private: System::Windows::Forms::Button^ button1;

	private: System::Windows::Forms::TextBox^ textBox1;


	private:

		/// 

		/// Required designer variable.

		/// 

		System::ComponentModel::Container ^components;


#pragma region Windows Form Designer generated code

		/// 

		/// Required method for Designer support - do not modify

		/// the contents of this method with the code editor.

		/// 

		void InitializeComponent(void)

		{

			this->label1 = (gcnew System::Windows::Forms::Label());

			this->button1 = (gcnew System::Windows::Forms::Button());

			this->textBox1 = (gcnew System::Windows::Forms::TextBox());

			this->SuspendLayout();

			// 

			// label1

			// 

			this->label1->AutoSize = true;

			this->label1->Location = System::Drawing::Point(35, 65);

			this->label1->Name = L"label1";

			this->label1->Size = System::Drawing::Size(0, 13);

			this->label1->TabIndex = 1;

			// 

			// button1

			// 

			this->button1->Location = System::Drawing::Point(38, 174);

			this->button1->Name = L"button1";

			this->button1->Size = System::Drawing::Size(75, 23);

			this->button1->TabIndex = 2;

			this->button1->Text = L"button1";

			this->button1->UseVisualStyleBackColor = true;

			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);

			// 

			// textBox1

			// 

			this->textBox1->Location = System::Drawing::Point(25, 25);

			this->textBox1->Name = L"textBox1";

			this->textBox1->Size = System::Drawing::Size(100, 20);

			this->textBox1->TabIndex = 3;

			// 

			// Form1

			// 

			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);

			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

			this->ClientSize = System::Drawing::Size(284, 264);

			this->Controls->Add(this->textBox1);

			this->Controls->Add(this->button1);

			this->Controls->Add(this->label1);

			this->Name = L"Form1";

			this->Text = L"Form1";

			this->ResumeLayout(false);

			this->PerformLayout();


		}

#pragma endregion

	private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

				 System::Int32 liczba_single;



				 liczba_single=System::Int32::Parse(textBox1->Text, System::Globalization::NumberStyles::HexNumber);


				 label1->Text=liczba_single.ToString();

			 }

	};

}

Z

liczba_single=System::Int32::Parse(textBox1->Text, System::Globalization::NumberStyles::HexNumber);

kompiluje jest bez przeszkód, ale z:

liczba_single=System::Int32::Parse(textBox1->Text, NumberStyles::HexNumber);

już nie, mimo że dołączyłem przestrzeń System::Globalization.


([alex]) #4

Ponieważ twoja przestrzeń nazywa się NumberStyles, zmień nazwę i po klopocie.


(przemekKK) #5

Ale metoda pochodzi z przestrzeni System::Globalization.

using namespace System::Globalization::NumberStyles;

Kompilator nie puszcza.


([alex]) #6

HexNumber - to nie metoda to jakaś stała.

Zaś NumberStyles to prawdopodobnie jakaś klasa nie namespace, dla tego nie możesz dać tego w using.

Zmień nazwę i po kłopocie.