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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:00:44+00:00 2026-05-16T22:00:44+00:00

class a { protected: const int _ID; public: a::a(int id){}; a::top(int num); }; class

  • 0
class a
{
protected:
  const int _ID;

public:
  a::a(int id){};
  a::top(int num);
};

class b : public a
{
  static int ok;
  b::b(int id):a(id){};
  a::top(ok);
}

int main()
{
  int t=5;
  b opj=b(t);
}

first why i get this compile error that solved only when i remove the const

non-static const member ‘const int Student::_ID’, can’t use default assignment operator –
instantiated from ‘void std::vector::_M_insert_aux(__gnu_cxx::__normal_iterator, const _Tp&) [with _Tp = Student, _Alloc = std::allocator]’

second

i have anther problem

undefined reference to b::ok

  • 1 1 Answer
  • 1 View
  • 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-16T22:00:44+00:00Added an answer on May 16, 2026 at 10:00 pm

    Second first: b::ok has been declared, but not defined. Someplace, (preferably b.cpp), you need to add:

      int b::ok;
    

    As for your first problem, _ID is const, it value cannot be changed — but, you never give it a value to start with. You have to assign it an initial value:

      protected:
          const int _ID = 1234;
    

    Now, you really should defined _ID as well, as we did with b::ok, but since it is const, the compiler may let you get away without doing that (some conditions apply).

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

Sidebar

Related Questions

public class A { protected int x; public A(int x) { this.x = x;
Consider this syntactically correct(?) pseudocode: class Event { public: virtual int getID() const =
I have this: public static class Domain { private const string sessionKey = NHib.SessionKey;
I have the following class to test: public abstract class Challenge { protected int
So i got a class like this: class Db { protected static $dbh =
class A // abstract class { protected: int m_iA; int m_iB; int m_iC; int
I have this code in base class protected virtual bool HasAnyStuff<TObject>(TObject obj) where TObject:class
Class parent { protected void myMethod() { if(someCodition) { //return this as well as
I have the code: class Point3D{ protected: float x; float y; float z; public:
When I try to serialize class with protected members, I get the following errors:

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.