simple namespace c++ question
i've created a C++ windows form project. i've added a c++ class(CompClass.cpp) to the same namespace where Form1.cpp exists. In the ClassView i can see both of these classes.
i've added a button control to the form1 and double-click it on design time.
private
: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {CompClass cc1;
}
};
As you see I wanted to define cc1 variable with the type of CompClass but when i build the solution following errors identified for the same line:
Error 1 error C2065: 'CompClass' : undeclared identifier c:\..Form1.h
Error 2 error C2146: syntax error : missing ';' before identifier 'cc1' c:\..Form1.h 86
Error 3 error C2065: 'cc1' : undeclared identifier c:\..\Form1.h 86
Below are the codes of Form1.h, CompClass.h, CompClass.cpp
Form1.h
#pragma
oncenamespace
NamespaceWork {usingnamespace System;usingnamespace System::ComponentModel;usingnamespace System::Collections;usingnamespace System::Windows::Forms;usingnamespace System::Data;usingnamespace System::Drawing;////// 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.///publicrefclass 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;}
}
private: System::Windows::Forms::Button^ button1;protected: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->button1 = (gcnew System::Windows::Forms::Button());this->SuspendLayout();//// button1//this->button1->Location = System::Drawing::Point(110, 72);this->button1->Name = L"button1";this->button1->Size = System::Drawing::Size(75, 23);this->button1->TabIndex = 0;this->button1->Text = L"button1";this->button1->UseVisualStyleBackColor =true;this->button1->Click +=gcnew System::EventHandler(this, &Form1::button1_Click);//// Form1//this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;this->ClientSize = System::Drawing::Size(292, 266);this->Controls->Add(this->button1);this->Name = L"Form1";this->Text = L"Form1";this->ResumeLayout(false);}
#pragma
endregionprivate: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {CompClass cc1;
}
};
}
CompClass.h
#pragma
onceusing
namespace System;using
namespace System::ComponentModel;using
namespace System::Collections;using
namespace System::Diagnostics;namespace
NamespaceWork {////// Summary for CompClass///publicrefclass CompClass :public System::ComponentModel::Component{
public:CompClass(
void){
InitializeComponent();
////TODO: Add the constructor code here//}
CompClass(System::ComponentModel::IContainer ^container)
{
////// Required for Windows.Forms Class Composition Designer support///container->Add(
this);InitializeComponent();
}
void PrintToScreen(void){
}
protected:////// Clean up any resources being used.///~CompClass()
{
if (components){
delete components;}
}
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){
components =
gcnew System::ComponentModel::Container();}
#pragma
endregion};
}
ref
class CompClass{
public
:CompClass(
void);void PrintToScreen(void);};
#include
"StdAfx.h"#include
"CompClass.h"CompClass::CompClass(
void){
Console::WriteLine(
"serdar");}
void
CompClass::PrintToScreen(void){
Console::WriteLine(
"Printed to screen");}

