Window Form otwarciem nowego

0

Nie wiem czemu ale podczas kompilacji wyskakuje mi błąd

Error	4	error C2065: 'TModification' : undeclared identifier
 
Error	5	error C2065: 'new_Window' : undeclared identifier	

A połączyłem oba formy ze sobą jak pokazano tutaj
http://kurs-c-plus-plus.cba.pl/?page_id=437

Oto kod moich form ( button 3 odpowiada za otwarcie nowego forma Modification )

#pragma once
#include <string>
#include <fstream>
#include "Str.h"
#include <vector>
#include <iostream>
#include <conio.h>
#include "Nawigacja.h"
#include "TModification.h"
#include <stdio.h> 


namespace Project2 {

	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 std;

	/// <summary>
	/// Summary for TMenu
	/// </summary>
	public ref class TMenu : public System::Windows::Forms::Form
	{
	public:
		
		vector<string> *v  ;

		TMenu(void)
		{
			InitializeComponent();
			v= new vector<string>;
			//
			//TODO: Add the constructor code here
			//

		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~TMenu()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 

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



	public: 
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(109, 176);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Zakończ";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &TMenu::button1_Click_1);
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(109, 43);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(75, 23);
			this->button3->TabIndex = 2;
			this->button3->Text = L"Wyszukaj";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &TMenu::button3_Click);
			// 
			// TMenu
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 261);
			this->Controls->Add(this->button3);
			this->Controls->Add(this->button1);
			this->Name = L"TMenu";
			this->Text = L"TMenu";
			this->Load += gcnew System::EventHandler(this, &TMenu::TMenu_Load);
			this->ResumeLayout(false);

		}
#pragma endregion

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


			 }

	public: System::Void TMenu_Load(System::Object^  sender, System::EventArgs^  e) {
				load_data();
			}

			
	
private: System::Void button1_Click_1(System::Object^  sender, System::EventArgs^  e) {
			 Application::Exit();
		 }

		 void load_data(){
				int numerWiersza = 0;

				string wiersz;
				ifstream f("przystanki.txt");
				if (f.is_open())
				{
					while (getline (f, wiersz,'\t'))
					{						
						v->push_back(wiersz); 						
					}
				}
				f.close();
			}

			void show_data(){
				int i = 0 ; 

				for (i = 0; i<v->size();i++)
				MessageBox::Show(gcnew String(v->at(i).c_str()));
			}

private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 TModification^ new_Window = gcnew TModification;
				 this->Hide();

				 new_Window->ShowDialog();
				 this->Show();
		 }
};
}
 

a to początek TModification

#pragma once
#include <string>
#include "TMenu.h"

namespace Project2 {
0

I gdzie tu deklaracja klasy TModification ?

0
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
             TModification^ new_Window = gcnew TModification;
                 this->Hide();
 
                 new_Window->ShowDialog();
                 this->Show();
         } 
0

Cała klasa Tmodification

#pragma once
#include <string>
#include "TMenu.h"

namespace Project2 {
	using namespace std; 
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for TModification
	/// </summary>
	public ref class TModification : public System::Windows::Forms::Form
	{
	public:
		TModification(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~TModification()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  btn_Add_Line;
	protected: 

	private: System::Windows::Forms::TextBox^  tbx_Name;
	private: System::Windows::Forms::ComboBox^  cmb_Stop;




	private: System::Windows::Forms::ComboBox^  cmb_Type;

	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::RichTextBox^  rtbx_List_Stop;

	private: System::Windows::Forms::Button^  btn_Add_Stop;
	private: System::Windows::Forms::Button^  btn_Delete_Stop;


	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->btn_Add_Line = (gcnew System::Windows::Forms::Button());
			this->tbx_Name = (gcnew System::Windows::Forms::TextBox());
			this->cmb_Stop = (gcnew System::Windows::Forms::ComboBox());
			this->cmb_Type = (gcnew System::Windows::Forms::ComboBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->rtbx_List_Stop = (gcnew System::Windows::Forms::RichTextBox());
			this->btn_Add_Stop = (gcnew System::Windows::Forms::Button());
			this->btn_Delete_Stop = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// btn_Add_Line
			// 
			this->btn_Add_Line->Location = System::Drawing::Point(342, 52);
			this->btn_Add_Line->Name = L"btn_Add_Line";
			this->btn_Add_Line->Size = System::Drawing::Size(75, 23);
			this->btn_Add_Line->TabIndex = 0;
			this->btn_Add_Line->Text = L"Dodaj Linie ";
			this->btn_Add_Line->UseVisualStyleBackColor = true;
			this->btn_Add_Line->Click += gcnew System::EventHandler(this, &TModification::btn_Add_Line_Click);
			// 
			// tbx_Name
			// 
			this->tbx_Name->Location = System::Drawing::Point(40, 26);
			this->tbx_Name->Name = L"tbx_Name";
			this->tbx_Name->Size = System::Drawing::Size(100, 20);
			this->tbx_Name->TabIndex = 1;
			// 
			// cmb_Stop
			// 
			this->cmb_Stop->FormattingEnabled = true;
			this->cmb_Stop->Location = System::Drawing::Point(37, 156);
			this->cmb_Stop->Name = L"cmb_Stop";
			this->cmb_Stop->Size = System::Drawing::Size(121, 21);
			this->cmb_Stop->TabIndex = 2;
			this->cmb_Stop->SelectedIndexChanged += gcnew System::EventHandler(this, &TModification::comboBox1_SelectedIndexChanged);
			// 
			// cmb_Type
			// 
			this->cmb_Type->FormattingEnabled = true;
			this->cmb_Type->Items->AddRange(gcnew cli::array< System::Object^  >(4) {L"Autobusowy", L"Autobusowy/Tranwajowy", L"Tranwajowy", 
				L"Metro"});
			this->cmb_Type->Location = System::Drawing::Point(40, 81);
			this->cmb_Type->Name = L"cmb_Type";
			this->cmb_Type->Size = System::Drawing::Size(121, 21);
			this->cmb_Type->TabIndex = 3;
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(40, 62);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(25, 13);
			this->label1->TabIndex = 4;
			this->label1->Text = L"Typ";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(37, 141);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(58, 13);
			this->label2->TabIndex = 5;
			this->label2->Text = L"Przystanki ";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(43, 7);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(40, 13);
			this->label3->TabIndex = 6;
			this->label3->Text = L"Nazwa";
			// 
			// rtbx_List_Stop
			// 
			this->rtbx_List_Stop->Location = System::Drawing::Point(230, 104);
			this->rtbx_List_Stop->Name = L"rtbx_List_Stop";
			this->rtbx_List_Stop->Size = System::Drawing::Size(173, 136);
			this->rtbx_List_Stop->TabIndex = 7;
			this->rtbx_List_Stop->Text = L"";
			// 
			// btn_Add_Stop
			// 
			this->btn_Add_Stop->Location = System::Drawing::Point(38, 196);
			this->btn_Add_Stop->Name = L"btn_Add_Stop";
			this->btn_Add_Stop->Size = System::Drawing::Size(63, 23);
			this->btn_Add_Stop->TabIndex = 8;
			this->btn_Add_Stop->Text = L"Dodaj";
			this->btn_Add_Stop->UseVisualStyleBackColor = true;
			// 
			// btn_Delete_Stop
			// 
			this->btn_Delete_Stop->Location = System::Drawing::Point(119, 196);
			this->btn_Delete_Stop->Name = L"btn_Delete_Stop";
			this->btn_Delete_Stop->Size = System::Drawing::Size(60, 23);
			this->btn_Delete_Stop->TabIndex = 9;
			this->btn_Delete_Stop->Text = L"Usuń";
			this->btn_Delete_Stop->UseVisualStyleBackColor = true;
			// 
			// TModification
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(466, 261);
			this->Controls->Add(this->btn_Delete_Stop);
			this->Controls->Add(this->btn_Add_Stop);
			this->Controls->Add(this->rtbx_List_Stop);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->cmb_Type);
			this->Controls->Add(this->cmb_Stop);
			this->Controls->Add(this->tbx_Name);
			this->Controls->Add(this->btn_Add_Line);
			this->Name = L"TModification";
			this->Text = L"TModification";
			this->Load += gcnew System::EventHandler(this, &TModification::TModification_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: System::Void btn_Add_Line_Click(System::Object^  sender, System::EventArgs^  e) {
				 String^ name  = tbx_Name->Text;
				
			 }
private: System::Void TModification_Load(System::Object^  sender, System::EventArgs^  e) {
			 cmb_Stop->Items->Add("lol");
			 
			 
		 }
};
}
 
1

Więc wywal #include "TMenu.h" z tego pliku i po sprawie.

0

a teraz nie mogę jakby sięgnąć do mojej zmiennej wektorowej "v" .... chciałbym aby w klasie TMain wczytywane były dane a w TModification wpisane jako iteam w ComboBox...

1

Dla tego w C++ wymyślono część .h oraz cześć .cpp
Nie masz szans na krzyżowe użycie dopóki nie rozbijesz to na h i cpp

0

no tutaj też są małe komplikacje :) bo jak wrzucę moją metodę odpowiadającą za pobieranie danych to ona nie widzi vector v.
plik TMenu.cpp

 #include "TMenu.h"



namespace Project2 {

 void load_data(){
				int numerWiersza = 0;

				string wiersz;
				ifstream f("przystanki.txt");
				if (f.is_open())
				{
					while (getline (f, wiersz,'\t'))
					{						
						v->push_back(wiersz); 						
					}
				}
				f.close();
			}

 void show_data(){
				int i = 0 ; 

				for (i = 0; i<v->size();i++)
				MessageBox::Show(gcnew String(v->at(i).c_str()));
			}
}
1

Ja też nie widzę.
Musisz rozbić na deklaracje w klasie w .h: void load_data();
Oraz implementacje w .cpp: void TMenu::load_data() { ... }

0

fajnie sobie poukładałem sobie kod tylko kwestia jak mam sięgnąć z innej klasy (z TModification) do zmiennej v ?
próbuje to zrobić przez metodę a więc :

TMenu

	TMenu::TMenu(){
		InitializeComponent();
		v = new vector<string>; 
	}

	vector<string> TMenu::return_v(int i){
		return v[i];
	} 

TModification

 private: System::Void TModification_Load(System::Object^  sender, System::EventArgs^  e) {
			 cmb_Stop->Items->Add(TMenu::return_v(0))
;
}
  1. drugie moje pytanie czy mogę przekazać w jakiś sposób cały wektor ? bo zapis
vector<string> TMenu::return_v(){
		return v;

nie działa

0

Bo v u ciebie to zapewne vector* (skoro robisz new) a nie vector.
Zamiast vectora użyj dotnetowego List<>.

List<String^> ^v;

...

v = gcnew List<String^>();

...

List<String^>^ TMenu::return_v()
{
        return v;
}
0

a na vectorze tego nie zrobię ? xd bo dużo rzeczy musiałbym zmieniać :)

0

Możesz to nawet na pliku zrobić.

0

i mam problem z tą listą juz ..

	2	IntelliSense: List is not a template	
 

chyba że dodam

#include <list> 

private: list<String^> *v; 

chyba że o to Ci chodziło, ale wtedy nadal mam wzkaźnik.

1 użytkowników online, w tym zalogowanych: 0, gości: 1