Sound designer/Game Developer based in South Yorkshire, UK

Report article RSS Feed setting const in an instance of a class c++

Posted by TommyGoogle on Aug 23rd, 2013

cpp code:
#include <cstdio>


class aclass
{
public:
    const int intvalue;
    const int intvalue2;

    aclass(int val = 89) : intvalue(val),intvalue2(val)//constructor
    {
     //stuff - intvalue = 23, but it could not be set here!
    }
};

main()
{
    aclass *nm = new aclass(66);
    aclass &amp;mm = *nm;

    printf ("%d\n" , mm.intvalue);
}
 
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Level
Avatar
Avatar
Offline Since
Jan 21, 2014
Country
United Kingdom United Kingdom
Gender
Male
Member Watch
Track this member
Blog
Browse
Blogs
Views
87 (1 today)
Report Abuse
Report article