Sound designer/Game Developer based in South Yorkshire, UK

Report content RSS feed setting const in an instance of a class c++

Posted by on

#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

You are not logged in, your comment will be anonymous unless you join the community. Or sign in with your social account:

Level
Avatar
Avatar
Last Online
Country
United Kingdom United Kingdom
Gender
Male
Friends
Become friends
Member watch
Start tracking
Blog
Browse
Blogs
Share