If I have a class called cdrom, and one of the member functions is loadinfo, what is the difference in these calls?

cd1.loadinfo

cd1->loadinfo

I ask because my compiler is choking on the first and actually asking me if I meant to do the second.

Consider the following

// A variable of class cdrom on the stack
cdrom cdrom1;
// invoke the loadinfo() member function
cdrom1.loadinfo();

// Allocate a variable of class cdrom on the heap
cdrom * cdrom_ptr = new cdrom;
// invoke the loadinfo() member function
cdrom_ptr->loadinfo();

So the difference is static vs dynamic allocation?

static actually is not a good word to use here. Let's say for simplicity's sake that, if you have a pointer to a struct/class to work with, then you use the -> operator to access member variables/functions through that pointer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.