A pointer to something that needs to be constant.
I've seen this code before...
type *getNodeList() const;
The problem with it is that it should not compile. The reason?
The "const" at the end of the method prototype says that you wont change *this. However, you are giving no guarantee that you'll keep this promise because you are returning type *.
For all the compiler knows, you're going to be an evil person and use the pointer to change *this. However, some compilers give you the benefit of the doubt and will happily compile this for you.
Thankfully, gcc is not one of them. For this to compile you have to ensure that you won't change *this. To guarantee this you need to make the pointer a constant type, type const * (I like this method of placing const to the right of the type but const type * means the same thing so it's no big deal.)
Therefore you get.
type const *getNodeList() const;
This should compile because you now have enough guaratees in place that the compiler will trust you. Of course you can override this type of behavor but I don't recommend it.
Wednesday, May 20, 2009
Tuesday, January 23, 2007
So here's my first example of using the Evolution Sharp Library.
This you can now replace the "A Name" with a name in your contact listing in Evolution and see their Full name on the console.
NOTE (2009-19-05): This wasn't the first post, but I left it here because I needed a place to scribble some notes down. I had just gotten a Blogger account back in late 2006 and was using Drivel at the time to post to blogger. I was just putting notes that I need to carry around with me on the blog not any really useful information except for me.
I don't know what project I was working on when I posted this note to my blog. In late 2008 I remembered my Blogger account and in 2009 I chose to use it more than my Livejournal account. Before I started using the account again I decided to clean it all up and remove a lot of the posts that were just notes and didn't really make any sense at all.
This post somehow survived the great purge and is one of the few post still left from those days. I am leaving it here just because it's a little piece of my history.
using System;
using Evolution;
class MyDemoClass {
public static void Main(string [] args){
Evolution.Book myBook = new Evolution.Book();
Evolution.BookQuery bq;
bq = Evolution.BookQuery.AnyFieldContains("A Name");
Evolution.Contact [] con;
myBook.Open(false);
con = myBook.GetContacts(bq);
foreach(Evolution.Contact c in con)
Console.WriteLine(c.FullName);
}
}
This you can now replace the "A Name" with a name in your contact listing in Evolution and see their Full name on the console.
NOTE (2009-19-05): This wasn't the first post, but I left it here because I needed a place to scribble some notes down. I had just gotten a Blogger account back in late 2006 and was using Drivel at the time to post to blogger. I was just putting notes that I need to carry around with me on the blog not any really useful information except for me.
I don't know what project I was working on when I posted this note to my blog. In late 2008 I remembered my Blogger account and in 2009 I chose to use it more than my Livejournal account. Before I started using the account again I decided to clean it all up and remove a lot of the posts that were just notes and didn't really make any sense at all.
This post somehow survived the great purge and is one of the few post still left from those days. I am leaving it here just because it's a little piece of my history.
Subscribe to:
Posts (Atom)