C3767 error with regex
-
Wednesday, January 04, 2006 11:59 PM
Hi all,
I'm very new to windows development (only have taken classes with c++ in linux) anyways, I keep getting this error and would like to know why.
myapp\MainWindow.h(263) : error C3767: 'System::Text::RegularExpressions::Regex::Regex': candidate function(s) not accessible
Here is my code:
#pragma once
namespace MyApp {
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::IO;
using namespace System::Text::RegularExpressions;
/// <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 MainWindow : public System::Windows::Forms::Form
{
public:
MainWindow(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MainWindow()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
protected:
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ openToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ saveToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
private: System::Windows::Forms::RichTextBox^ richTextBox1;
private: System::Windows::Forms::ToolStripMenuItem^ processToolStripMenuItem;
private: System::Windows::Forms::RichTextBox^ richTextBox2;
private: System::Windows::Forms::SplitContainer^ splitContainer1;
private: System::Windows::Forms::StatusStrip^ statusStrip1;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel1;
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->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->openToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->saveToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->processToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
this->splitContainer1 = (gcnew System::Windows::Forms::SplitContainer());
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
this->toolStripStatusLabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->menuStrip1->SuspendLayout();
this->splitContainer1->Panel1->SuspendLayout();
this->splitContainer1->Panel2->SuspendLayout();
this->splitContainer1->SuspendLayout();
this->statusStrip1->SuspendLayout();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->fileToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(743, 24);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->openToolStripMenuItem,
this->saveToolStripMenuItem, this->processToolStripMenuItem, this->toolStripSeparator1, this->exitToolStripMenuItem});
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
this->fileToolStripMenuItem->Size = System::Drawing::Size(35, 20);
this->fileToolStripMenuItem->Text = L"File";
//
// openToolStripMenuItem
//
this->openToolStripMenuItem->Name = L"openToolStripMenuItem";
this->openToolStripMenuItem->Size = System::Drawing::Size(122, 22);
this->openToolStripMenuItem->Text = L"Open";
this->openToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainWindow::openToolStripMenuItem_Click);
//
// saveToolStripMenuItem
//
this->saveToolStripMenuItem->Name = L"saveToolStripMenuItem";
this->saveToolStripMenuItem->Size = System::Drawing::Size(122, 22);
this->saveToolStripMenuItem->Text = L"Save";
this->saveToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainWindow::saveToolStripMenuItem_Click);
//
// processToolStripMenuItem
//
this->processToolStripMenuItem->Name = L"processToolStripMenuItem";
this->processToolStripMenuItem->Size = System::Drawing::Size(122, 22);
this->processToolStripMenuItem->Text = L"Process";
this->processToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainWindow::processToolStripMenuItem_Click);
//
// toolStripSeparator1
//
this->toolStripSeparator1->Name = L"toolStripSeparator1";
this->toolStripSeparator1->Size = System::Drawing::Size(119, 6);
//
// exitToolStripMenuItem
//
this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
this->exitToolStripMenuItem->Size = System::Drawing::Size(122, 22);
this->exitToolStripMenuItem->Text = L"Exit";
this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainWindow::exitToolStripMenuItem_Click);
//
// richTextBox1
//
this->richTextBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->richTextBox1->Location = System::Drawing::Point(3, 3);
this->richTextBox1->Name = L"richTextBox1";
this->richTextBox1->Size = System::Drawing::Size(737, 216);
this->richTextBox1->TabIndex = 2;
this->richTextBox1->Text = L"";
this->richTextBox1->WordWrap = false;
//
// richTextBox2
//
this->richTextBox2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->richTextBox2->Location = System::Drawing::Point(3, 3);
this->richTextBox2->Name = L"richTextBox2";
this->richTextBox2->Size = System::Drawing::Size(740, 200);
this->richTextBox2->TabIndex = 3;
this->richTextBox2->Text = L"";
this->richTextBox2->WordWrap = false;
this->richTextBox2->TextChanged += gcnew System::EventHandler(this, &MainWindow::richTextBox2_TextChanged);
//
// splitContainer1
//
this->splitContainer1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->splitContainer1->Location = System::Drawing::Point(0, 27);
this->splitContainer1->Name = L"splitContainer1";
this->splitContainer1->Orientation = System::Windows::Forms::Orientation::Horizontal;
//
// splitContainer1.Panel1
//
this->splitContainer1->Panel1->Controls->Add(this->richTextBox1);
//
// splitContainer1.Panel2
//
this->splitContainer1->Panel2->Controls->Add(this->richTextBox2);
this->splitContainer1->Size = System::Drawing::Size(743, 432);
this->splitContainer1->SplitterDistance = 222;
this->splitContainer1->TabIndex = 4;
//
// statusStrip1
//
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->toolStripStatusLabel1});
this->statusStrip1->Location = System::Drawing::Point(0, 449);
this->statusStrip1->Name = L"statusStrip1";
this->statusStrip1->Size = System::Drawing::Size(743, 22);
this->statusStrip1->TabIndex = 5;
this->statusStrip1->Text = L"statusStrip1";
//
// toolStripStatusLabel1
//
this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
this->toolStripStatusLabel1->Size = System::Drawing::Size(28, 17);
this->toolStripStatusLabel1->Text = L"Test";
this->toolStripStatusLabel1->Click += gcnew System::EventHandler(this, &MainWindow::toolStripStatusLabel1_Click);
//
// MainWindow
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(743, 471);
this->Controls->Add(this->statusStrip1);
this->Controls->Add(this->splitContainer1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"MainWindow";
this->Text = L"HTML Formatter";
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->splitContainer1->Panel1->ResumeLayout(false);
this->splitContainer1->Panel2->ResumeLayout(false);
this->splitContainer1->ResumeLayout(false);
this->statusStrip1->ResumeLayout(false);
this->statusStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
richTextBox1->LoadFile(openFileDialog1->FileName, RichTextBoxStreamType::PlainText);
}
}
private: System::Void saveToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
richTextBox1->SaveFile(saveFileDialog1->FileName, RichTextBoxStreamType::PlainText);
}
}
private: System::Void processToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
// all kinds of stuff here
// maybe make a class to do it
String^ strng = gcnew String("Halo");
richTextBox2->Text = strng;
Regex^ rx = gcnew Regex();
strng = rx->Replace(richTextBox1->Text(), "<[^>]*>", "");
}
private: System::Void richTextBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void toolStripProgressBar1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void toolStripStatusLabel1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
All Replies
-
Thursday, January 05, 2006 11:35 AMModerator
The default constructor for Regex is protected, which means you cannot access it (IIRC, it was made like this to stop people using Regex incorrectly). However, since the Regex::Replace overload you're trying to use is static, there's no need to instantiate a Regex object. You can just call the method directly:
System::Void processToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{// all kinds of stuff here maybe make a class to do it
String^ strng =
gcnew String("Halo");
richTextBox2->Text = strng;
// Regex^ rx = gcnew Regex();
strng = Regex::Replace(richTextBox1->Text, "<[^>]*>", "");
}

