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 7589477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:10:10+00:00 2026-05-30T20:10:10+00:00

I am new to visual C++. I wrote my class, but it has error

  • 0

I am new to visual C++. I wrote my class, but it has error

Error 1 error C3845: ‘CRegistration::list1’: only static data members can be initialized inside a ref class or value type c:\users\marco\desktop\cs351\hw3\project3\CRegistration.h 44 1 Project3

I understand the compiler has said what the error is. However, I don’t understand what it means. The following is my code

#pragma once

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::Collections;
using namespace System::Collections::Generic;


public ref class CRegistration
{
public: 

    CRegistration(void){

        ClickBoxRecord = 0;

        ClickBoxRecord = 0;


    };//end constructor

    void SetRadioRecord(int flag){ RadioRecordRecord = flag; }

    void SetClickBoxRecord(int flag){ ClickBoxRecord = flag; }

    int GetRadioRecordRecord(){return RadioRecordRecord}

    int GetClickBoxRecord(){return ClickBoxRecord}



protected:

private:

    int RadioRecordRecord;

    int ClickBoxRecord;

    LinkedList< int > list1 = gcnew LinkedList< int >();

    LinkedList< String^ > ^list2 = gcnew LinkedList< String^ >();

    LinkedList< String^ > ^list3 = gcnew LinkedList< String^ >();

    LinkedList< String^ > ^list4 = gcnew LinkedList< String^ >();

    LinkedList< String^ > ^list5 = gcnew LinkedList< String^ >();


};//end ref class
  • 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-05-30T20:10:11+00:00Added an answer on May 30, 2026 at 8:10 pm

    Are you trying to learn C++ or are you trying to learn CLI?

    // native C++
    #include <list>
    #include <string>
    
    std::list<int> list1;
    std::list<double> list2;
    std::list<std::string> list3;
    std::list<std::string> list4;
    std::list<std::string> list5;
    

    P.S.

    The problem is your inline initialization of non-static members list1 through list5. In C++ initialization of non-static members is done in an initializer list or the body of a constructor normally. In C++ we generally use the stack as much as possible and only use the heap when we have to as memory management is important.

    // C++/CLI
    
    // you can either make a list of each
    LinkedList< int > list1;    // list of int
    LinkedList< double > list2; // list of double
    LinkedList< String > list3; // list of String
    
    // or make an object that has one of each
    public ref class AllThree {
        public:
           // members
           String str;
           double dbl;
           int i;
    };
    
    // and make a list of that object
    LinkedList<AllThree> list4; // list of AllThree 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have wrote a class (a snippet is below) which have some data members
I'm new to Visual C# Studio (actually using the Express edition, but another developer
I created a new Visual Studio Setup project with VS 2008. I use it
I've just got the new Visual Studio 2010 Ultimate and Javascript Intellisense is not
Often times a developer on my team will create a new Visual Studio project
I am currently trying to set up a new visual studio 2008 solution while
I am new to visual studio/asp.net so please bear with me. Using vs 2005
I'm fairly new to Visual Studio and am wondering how best to plan for
I'm new to Visual C++, .NET, and the Windows world of programming (coming from
I'm completely new to Visual Studio and I'm having some trouble getting a project

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.