1

I have this Word.cc that is like string class for manipulating words. I overloaded operator << as friend function, but when i keep getting this "Address of Word a() will evaluate as true". Could you comment on where I might be wrong? The code I use in main is the following.

int main()
{
    Word a();
    cout<<a;
    return 0;
}

Word::Word()
{
    init("");
}

void Word::init(char *c,char *stoppers)
{
    char *temp="\0";

    if(c==NULL)
        c=temp;

    size=strlen(c)==0 ? DEFAULT_SIZE :(strlen(c)+1+DEFAULT_SIZE)/DEFAULT_SIZE*DEFAULT_SIZE;
    wd=new char[size+1];
    delimiters=new char[strlen(stoppers)+1];

    strcpy(wd,c);
    strcpy(delimiters,stoppers);
    count=strlen(wd);
}
ostream & operator<<(ostream &out,const Word &b)
{
    out<<b.wd;   
    return out;
}
joce
  • 9,624
  • 19
  • 56
  • 74
teamaster
  • 403
  • 2
  • 6
  • 16
  • 1
    possible duplicate of [Is no parentheses on a C++ constructor with no arguments a language standard?](http://stackoverflow.com/questions/2318650/is-no-parentheses-on-a-c-constructor-with-no-arguments-a-language-standard) – Bo Persson Aug 04 '12 at 17:33

1 Answers1

5

Most vexing parse:

Word a();

should be

Word a;
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625