Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:47:53+00:00 2026-06-11T17:47:53+00:00

Im trying to add new class to existing project. My class work corectly when

  • 0

Im trying to add new class to existing project. My class work corectly when it was under System::Windows::Forms::Form class inside Windows Form Application Project. I want to add my class to that project because i want all classes in different files. But when i want to compile I got error “syntax error : identifier ‘String'”. When i delete String object everything can be compiled. Where’s problem ?

#ifndef ConGen
#define ConGen

template <class T> 
ref class GenerateControls
{

public:
    GenerateControls(int i , int j, int k,int l, int m)//, String ^ n)//, int o, int p)
    : size(i),x(j),y(k),rozstawx(l),rozstawy(m), name(n), sizex(o), sizey(p)
    {
        tablica = gcnew array < T ^ >(size);

        for ( int j = 0 ; j < i ; ++j)
        {
            tablica[j] = gcnew T(); 
            tablica[j]->Name = String::Concat(n,Convert::ToString(j));
            tablica[j]->Location = System::Drawing::Point(x+rozstawx*j,y+rozstawy*j);
            //tablica[j]->Size = System::Drawing::Size(sizex,sizey);
            tablica[j]->AutoSize = true;
            tablica[j]->Visible = true;
        }

    }
    ~GenerateControls()
    {
        //for ( int j = 0 ; j < size ; ++ j )
        //{
        //}
    }


property int Size
{
    void set(int value)
    {
        //if(value < 0 ) throw
        size=value;
    }
    int get()
    {
        return size;
    }
}
property array< T ^ > ^ Tablica
{
    array<T ^ > ^ get()
    {
        return tablica;
    }
}

void SetVisible ( int i)
{
    for( int j = 0 ; j < size ; ++j)
    {
        if ( j < i ) tablica[j]->Visible = true;
        else tablica[j]->Visible = false;
    }

}

void SetPosition( int x, int y, int odleglosc_x, int odleglosc_y, int ile)
{
    for ( int i = 0 ; i<ile ; ++i)
    {
        Tablica[i]->Location = System::Drawing::Point(x+odleglosc_x*i,y+odleglosc_y*i);
    }
}

private:
    array < T ^ > ^ tablica;
    int size;
    int x;
    int y;
    int rozstawx;
    int rozstawy;
    int sizex;
    int sizey;
//  String  ^ name;
};


#endif

I want to participate my code to few classes but something weird is happened. This is my Form class:

#pragma once
#include "ConGen.h"

namespace Trening {

        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Data::SqlClient;
        using namespace System::Drawing;


        public ref class okno2 : public System::Windows::Forms::Form
        {
        public:
                okno2(void)
                {
                        InitializeComponent();
                }

        protected:

                ~okno2()
                {
                        if (components)
                        {
                                delete components;
                        }
                }

        private:

        System::ComponentModel::Container ^components;

        System::Windows::Forms::TabControl ^ tabcontrol;
        System::Windows::Forms::TabPage ^ tabpage1;
        System::Windows::Forms::TabPage ^ tabpage2;
        System::Windows::Forms::TabPage ^ tabpage3;

        System::Data::SqlClient::SqlConnection ^ sqlcon;

        GenerateControls < System::Windows::Forms::TextBox > ^ tb1;
        GenerateControls < System::Windows::Forms::TextBox > ^ tb2;
        GenerateControls < System::Windows::Forms::TextBox > ^ tb3;

        GenerateLabels < System::Windows::Forms::Label > ^ lb1;
        GenerateLabels < System::Windows::Forms::Label > ^ lb2;
        GenerateLabels < System::Windows::Forms::Label > ^ lb3;

        array < String ^ > ^ stringtabs1;
        array < String ^ > ^ stringtabs2;
        array < String ^ > ^ stringtabs3;

        array < String ^ > ^ textboxtabs1;
        array < String ^ > ^ textboxtabs2;
        array < String ^ > ^ textboxtabs3;

        int clientwidth;
        int clientheight;


#pragma region Windows Form Designer generated code

                void InitializeComponent(void)
                {

                        clientwidth = 300;
                        clientheight = 300;

                        this->tabcontrol = gcnew System::Windows::Forms::TabControl();
                        this->tabpage1 = gcnew System::Windows::Forms::TabPage();
                        this->tabpage2 = gcnew System::Windows::Forms::TabPage();
                        this->tabpage3 = gcnew System::Windows::Forms::TabPage();

                        this->tabcontrol->SuspendLayout();
                        this->tabpage1->SuspendLayout();
                        this->tabpage2->SuspendLayout();
                        this->tabpage3->SuspendLayout();

                        // tabcontrol

                        this->tabcontrol->Alignment = System::Windows::Forms::TabAlignment::Top;
                        this->tabcontrol->Controls->Add(this->tabpage1);
                        this->tabcontrol->Controls->Add(this->tabpage2);
                        this->tabcontrol->Controls->Add(this->tabpage3);
                        this->tabcontrol->Dock = System::Windows::Forms::DockStyle::Fill;
                        this->tabcontrol->HotTrack = true;
                        this->tabcontrol->Location = System::Drawing::Point(0,0);
                        this->tabcontrol->Multiline = true;
                        this->tabcontrol->Name = L"tabcontrol";
                        this->tabcontrol->SelectedIndex = 0;
                        this->tabcontrol->ShowToolTips = true;
                        this->tabcontrol->Size = System::Drawing::Size(215,129);
                        this->tabcontrol->TabIndex =1;

                        // tb1 & lb1

                        tb1 = gcnew GenerateControls< System::Windows::Forms::TextBox >(10,85,80,0,30,"tb1",145,35);
                        //lb1 = gcnew GenerateLabels< System::Windows::Forms::Label >(10,20,80,0,30,"lb1",35,20);     <----------------------------- TU
                        // tabPage1

                        this->tabpage1->BackColor = System::Drawing::Color::PaleGreen;
                        this->tabpage1->Controls->AddRange(tb1->Tablica);
                        //this->tabpage1->Controls->AddRange(lb1->Tablica);
                        this->tabpage1->Location = System::Drawing::Point(4, 4);
                        this->tabpage1->Name = L"tabpage1";
                        this->tabpage1->Padding = System::Windows::Forms::Padding(3);
                        this->tabpage1->Size = System::Drawing::Size(207, 103);
                        this->tabpage1->TabIndex = 0;
                        this->tabpage1->Text = L"Dane";
                        this->tabpage1->ToolTipText = L"Informacje o użytkowniku";
                        this->tabpage1->UseVisualStyleBackColor = false;

                        //tb2 & lb2

                        tb2 = gcnew GenerateControls< System::Windows::Forms::TextBox >(10,85,80,0,30,"tb1",145,35);
                        //lb2 = gcnew GenerateLabels< System::Windows::Forms::Label >(10,20,80,0,30,"lb1",35,20);     <----------------------------- TU

                        // tabPage2

                        this->tabpage2->BackColor = System::Drawing::Color::Plum;
                        this->tabpage2->Controls->AddRange(tb2->Tablica);
                        //this->tabpage1->Controls->AddRange(lb2->Tablica);
                        this->tabpage2->Location = System::Drawing::Point(4, 4);
                        this->tabpage2->Name = L"tabpage2";
                        this->tabpage2->Padding = System::Windows::Forms::Padding(3);
                        this->tabpage2->Size = System::Drawing::Size(207, 103);
                        this->tabpage2->TabIndex = 1;
                        this->tabpage2->Text = L"Wymiary";
                        this->tabpage2->ToolTipText = L"Wymiary poszczególnych partii";
                        this->tabpage2->UseVisualStyleBackColor = false;

                        //tb3 & lb3

                        tb3 = gcnew GenerateControls< System::Windows::Forms::TextBox >(10,85,80,0,30,"tb1",145,35);
                        //lb3 = gcnew GenerateLabels< System::Windows::Forms::Label >(10,20,80,0,30,"lb1",35,20);     <----------------------------- TU
                        // tabPage3

                        this->tabpage3->BackColor = System::Drawing::Color::Plum;
                        this->tabpage3->Controls->AddRange(tb3->Tablica);
                        //this->tabpage1->Controls->AddRange(lb3->Tablica);
                        this->tabpage3->Location = System::Drawing::Point(4, 4);
                        this->tabpage3->Name = L"tabpage3";
                        this->tabpage3->Padding = System::Windows::Forms::Padding(3);
                        this->tabpage3->Size = System::Drawing::Size(207, 103);
                        this->tabpage3->TabIndex = 2;
                        this->tabpage3->Text = L"Osiągi";
                        this->tabpage3->ToolTipText = L"Twoje osiągi";
                        this->tabpage3->UseVisualStyleBackColor = false;


                        this->Controls->Add(this->tabcontrol);
                        this->tabcontrol->ResumeLayout(false);
                        this->tabpage1->ResumeLayout(false);
                        this->tabpage1->PerformLayout();
                        this->tabpage2->ResumeLayout(false);
                        this->tabpage2->PerformLayout();
                        this->tabpage3->ResumeLayout(false);
                        this->tabpage3->PerformLayout();

                        this->ResumeLayout(false);

                        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                        this->ClientSize = System::Drawing::Size(clientwidth, clientheight);
                        this->Name = L"Form1";
                        this->Text = L"Form1";
                        this->ResumeLayout(false);
                }
#pragma endregion

                 }

        };
}

And this is class GenerateControls & GenerateLabels (there are in one file because when they are split i can’t compile).

#ifndef ConGen
#define ConGen


using namespace System;
namespace Trening
{
        template <class T> 
        ref class GenerateControls
        {

        public:
                GenerateControls(int i , int j, int k,int l, int m, String ^ n, int o, int p)
                : size(i),x(j),y(k),rozstawx(l),rozstawy(m), name(n)//, sizex(o), sizey(p)
                {
                        tablica = gcnew array < T ^ >(size);

                        for ( int j = 0 ; j < i ; ++j)
                        {
                                tablica[j] = gcnew T();        
                                tablica[j]->Name = String::Concat(n,Convert::ToString(j));
                                tablica[j]->Location = System::Drawing::Point(x+rozstawx*j,y+rozstawy*j);
                                //tablica[j]->Size = System::Drawing::Size(sizex,sizey);
                                tablica[j]->AutoSize = true;
                                tablica[j]->Visible = true;
                        }

                }
                ~GenerateControls()
                {
                        //for ( int j = 0 ; j < size ; ++ j )
                        //{
                        //}
                }


        property int Size
        {
                void set(int value)
                {
                        //if(value < 0 ) throw
                        size=value;
                }
                int get()
                {
                        return size;
                }
        }
        property array< T ^ > ^ Tablica
        {
                array<T ^ > ^ get()
                {
                        return tablica;
                }
        }

        void SetVisible ( int i)
        {
                for( int j = 0 ; j < size ; ++j)
                {
                        if ( j < i ) tablica[j]->Visible = true;
                        else tablica[j]->Visible = false;
                }

        }

        void SetPosition( int x, int y, int odleglosc_x, int odleglosc_y, int ile)
        {
                for ( int i = 0 ; i<ile ; ++i)
                {
                        Tablica[i]->Location = System::Drawing::Point(x+odleglosc_x*i,y+odleglosc_y*i);
                }
        }

        void SetSize( int x, int y, int ile)
        {
                // if (ile > Size ) throw
                for ( int i = 0 ; i < ile ; ++i)
                {
                        Tablica[i]->Size = System::Drawing::Size(x, y);
                }
        }

        private:
                array < T ^ > ^ tablica;
                int size;
                int x;
                int y;
                int rozstawx;
                int rozstawy;
                int sizex;
                int sizey;
                String  ^ name;

        };

        #include "ConGen.h" // skopiowałem poprzez crtl + a całą klasę i zapomniałem usunąć tej linijki.
using namespace System;

template < class T >
        ref class GenerateLabels : public GenerateControls< T > //: public SetControlText< T >
        {
                public:

            GenerateLabels(int i , int j, int k,int l, int m, String ^ n, int o, int p)
                :GenerateControls( i,j,k,l,m,n,o,p)
                {
                }
                ~GenerateLabels()
                {
                }

                void SetText( array< String ^ > ^ name)
                {
                        int i = 0;
                        //if (name.Size != controlarray.Size ) throw 
                        for each ( String ^ str in name)
                        {
                                Tablica[i++]->Text = str;
                        }
                }

        };
}
#endif

With out code witch is marked “<——–Tu” i got error like these ( he is in first class okno2).

1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: tablica): (0x04000033).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: size): (0x04000034).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: x): (0x04000035).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: y): (0x04000036).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: rozstawx): (0x04000037).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: rozstawy): (0x04000038).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: sizex): (0x04000039).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: sizey): (0x0400003a).
1>Trening.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; fields: name): (0x0400003b).
1>Trening.obj : error LNK2022: metadata operation failed (801311D7) : Differing number of fields in duplicated types (Trening.GenerateControls<System::Windows::Forms::Label>): (0x02000005).
1>Trening.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: Trening.GenerateControls<System::Windows::Forms::Label>; interfaces: System.IDisposable): (0x09000002).
1>LINK : fatal error LNK1255: link failed because of metadata errors

I think something is wrong with GenerateLabels class. Because when instance of that class isn’t inicializet i got that errors. With GenerateControls everything works fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:47:54+00:00Added an answer on June 11, 2026 at 5:47 pm

    I don’t see a using namespace System; in your code. Did you trim that when copy/pasting to the web, or do you need to add it?

    I see you’re referencing System::Drawing::Point and System::Drawing::Size by their full namespaces, could be you just need the using directive for System::String.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a new class to a pre-existing web application in
Im new to asp.net mvc. I'm trying add new model class but it got
I'm trying to add a new ADO.Net Entity Data Model to an MVC project
I'm trying to add new object to existing organisational unit in Active Directory. Following
I'm trying to edit an existing .proto file in VS2010 to add a new
I am trying to add a new service method to my existing WCF web
I am trying to add three new table to my existing sqlite db and
I'm trying to add a Metadata partial class to an existing MVC using EF
I'm trying to add a new nova-compute node (KUubuntu 12.04) to my single node
I am trying to add a new record to my internal table and this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.