CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    5

    Unhappy help with undeclared identifiers

    I can't seem to fix this problem, seeing if you guys see anything that I am blindly missing.
    I get errors such as:

    1>c:\projects\lab2\lab2\word.cpp(64) : error C2065: 'five' : undeclared identifier
    1>c:\projects\lab2\lab2\word.cpp(75) : error C2065: 'five' : undeclared identifier
    1>c:\projects\lab2\lab2\word.cpp(76) : error C2065: 'twod' : undeclared identifier

    and every variable in my string arrays all have the same 'undeclared identifier' error. I am using the 'using namespace std;' so i dont see the problem.

    here is a short snippet of my code:


    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <stdio>

    using namespace std;

    int lengths(string* [], string [][]);

    int main(){

    string* five[5] = {boat, light, gray, mind, soul};
    string twod[3][2] = {{cat, dog, hamster},
    {bird, monkey, fish}};

    int lengths( *five[5], twod[3][2] );
    int iei( *five[5], twod[3][2] );

    return 0;
    }

    //Display the length of each string.

    int length(string *five[],string twod[][]){

    for(int x=0; x<5; x++){
    cout << "*five[" << x << "] ";
    cout << "has a length of " << five[x].length();
    }
    }

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: help with undeclared identifiers

    There's a lot wrong with that code. I'm not entirely sure where to begin.

    I guess for starters, I'm not sure why you're making "five" an array of string pointers. Why not just an array of strings? And the initializers should have double-quotes around them.

  3. #3
    Join Date
    Sep 2009
    Posts
    5

    Re: help with undeclared identifiers

    Well it was on the assignment sheet that "five" had to be a pointer. And thanks, I feel dumb that I didn't realize that one.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: help with undeclared identifiers

    There's a difference between a pointer and an array of pointers. Make sure you're absolutely clear on what's being asked of you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured