Forbids Declaration of '___' with no type

This is a discussion on Forbids Declaration of '___' with no type within the C++ Programming forums, part of the General Programming Boards category; I'm getting this error, "Forbids Declaration of '___' with no type", for just about every function I have in my ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    92

    Forbids Declaration of '___' with no type

    I'm getting this error, "Forbids Declaration of '___' with no type", for just about every function I have in my class and I have no idea what's wrong. Can any of you help me understand what's happening? I can elaborate more if needed.

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    92
    It's also telling me that a few of my operators can not be overloaded. I'm just declaring them like this:

    Code:
    Object operator[](int);

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,252
    Quote Originally Posted by warfang View Post
    I'm getting this error, "Forbids Declaration of '___' with no type", for just about every function I have in my class and I have no idea what's wrong. Can any of you help me understand what's happening? I can elaborate more if needed.
    Have you specified the return value types of all your methods? You can't leave that out. If a method returns nothing, it must be declared return type "void."

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    92
    In my header file:

    Code:
    int & operator[](int);
    In my .cpp file:

    Code:
    Object::operator[](int index){
        ....
        return &temp[0][0];
    }
    And that's how I have it set up.

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    two things:
    Code:
    int & Object::operator[](int index){
    //...
    }
    Also, you're returning a pointer, when you should be returning a reference (the compiler will complain when you fix the other errors).
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    92
    I don't get it. In the header I already stated what it was going to return. So I have to do it in both files?

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by warfang View Post
    I don't get it. In the header I already stated what it was going to return. So I have to do it in both files?
    yes - declaration should exactly match the definition of the function...
    The only thing you can skip in declaration - is var names, the rest - return type and var types should be the same
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  3. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  4. ISO C++ forbids declaration of
    By bhorrobi in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2003, 02:36 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21