Question

I know there are a lot of questions about this, but I've checked my program for common mistakes, and I can't seem to find any.

I'm getting these errors for the first line of my copy constructor in a file strlist.cpp:

ISO C++ forbids declaration of ‘Strlist’ with no type [-fpermissive] no ‘int StrList::Strlist(const StrList&)’ member function declared in class ‘StrList’

Here is that section:

 /* copy constructor */
 40 StrList::Strlist(const StrList& rhs)
 41 {
 42    intitList(&list);
 43    Struct Node *current = (rhs.list).head;
 44    while(current != NULL){
 45       AddFront(*(const MyString *)current->data);
 46       current = current->next;
 47    }
 48    reverse();
 49 }

Here is the copy constructor in my header file:

  5 #ifndef __STRLIST_H__
  6 #define __STRLIST_H__
 11 
 12 #include "mystring.h"
 13 #include "stdio.h"
 14 #include "stdlib.h"

 20 
 21 extern "C" {
 22 #include "mylist.h"
 23 }
 24 
 25 class StrList {
 26 
 27     public:
(......................)
 40 
 41         /*copy constructor */
 42         StrList(const StrList& rhs);
(..................)
105 };
106 
107 #endif

I included strlist.h in strlist.cpp, so I can't figure out what is wrong with this.

Thanks!!

Was it helpful?

Solution

ISO C++ forbids declaration of ‘Strlist’ with no type

StrList::Strlist(const StrList& rhs)
//          ^    

You should be extra-careful when reading error messages, the compiler is trying to help you!

OTHER TIPS

Simply change StrList::Strlist to StrList::StrList as the first way would not be referring to the constructor (wrong case on the List part)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top