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

  • Home
  • SEARCH
  • 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 7821033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:31:06+00:00 2026-06-02T07:31:06+00:00

I am using a structure in my program as below: public struct chromo_typ {

  • 0

I am using a structure in my program as below:

public struct chromo_typ
{
        public string   bits;  
        public float    fitness;

        chromo_typ(string bts, float ftns)
        {
            bits = bts;
            fitness = ftns;
        }
};

I am using the constructor defined in the struct i.e. chromo_typ(string bts, float ftns) in my main(). My main() contains the following code:

chromo_typ[] temp = new chromo_typ[VM_Placement.AlgorithmParameters.pop_size];

                    chromo_typ ct = new chromo_typ();

                    int cPop = 0;

                    //loop until we have created POP_SIZE new chromosomes
                    while (cPop < VM_Placement.AlgorithmParameters.pop_size)
                    {
                        // we are going to create the new population by grabbing members of the old population
                        // two at a time via roulette wheel selection.
                        string offspring1 = p.Roulette(TotalFitness, Population);
                        string offspring2 = p.Roulette(TotalFitness, Population);

                        //add crossover dependent on the crossover rate
                        p.Crossover(offspring1, offspring2);

                        //now mutate dependent on the mutation rate
                        p.Mutate(offspring1);
                        p.Mutate(offspring2);

                        //add these offspring to the new population. (assigning zero as their
                        //fitness scores)
                        temp[cPop++] = ct.chromo_typ(offspring1, 0.0f);
                        temp[cPop++] = ct.chromo_typ(offspring2, 0.0f);

                    }//end loop

I am getting the following error at temp[cPop++] = ct.chromo_typ(offspring1, 0.0f); and temp[cPop++] = ct.chromo_typ(offspring2, 0.0f);

Error: 'VM_Placement.Program.chromo_typ' does not contain a
definition for 'chromo_typ' and no extension method 'chromo_typ'
accepting a first argument of type 'VM_Placement.Program.chromo_typ'
could be found (are you missing a using directive or an assembly
reference?)

Am I using structure incorrectly? How can I resolve this?

  • 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-02T07:31:07+00:00Added an answer on June 2, 2026 at 7:31 am

    In this case, chromo_typ is a constructor, but you are calling it as an instance method. Constructors are used to construct an object, i.e.,

    temp[cPop++] = new chromo_typ(arg1, arg2);
    

    It is not a method that you can call on an instance of your type.

    On a side note, the canonical way to name types in C# is to use start with an uppercase letter and use camel case, i.e.,

    public struct ChromoTyp { }
    

    Of course, this is not a rule, but it is usually a good idea to follow the patterns already in use by the community.

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

Sidebar

Related Questions

I have a program with the general structure shown below. Basically, I have a
I'm working on a program using reactive-banana , and I'm wondering how to structure
I know it helps a lot if we structure our programs using classes, structs
I'm using Structure map and want to inject instance (constructed by container) into controller's
i have problem using LIKE structure in DB2 : for example: select * from
I want to create tree structure using web service. I have used bottom up
I am trying to create a wizard like structure using dialog boxes...So I replaced
I would like to display a directory structure using Gtk# widgets through F#, but
I am looking to sort an XML structure using XSLT using xsltproc: The xml
I would like copy just file.xml without folder structure using overlays like this: <overlays>

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.