declaration problem

This is a discussion on declaration problem within the C++ Programming forums, part of the General Programming Boards category; ok i have a program which has a set of array's for flights, and a function that runs at the ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    84

    declaration problem

    ok i have a program which has a set of array's for flights, and a function that runs at the start of the problem to fill the array

    anyway i want a print all flights option, and i have tried testing by printing 1 flight so far, but it says undelcared identifier.

    Code:
    // Cfunctions.cpp: implementation of the functions class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "functions.h"
    #include <iostream>
    #include <windows.h>
    #include <fstream.h>
    #include <conio.h>
    #include <stdlib.h>
    #include "flights.h"
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    Cfunctions::Cfunctions()
    {
    
    }
    
    Cfunctions::~Cfunctions()
    {
    
    }
    
    Cfunctions::Printall()
    {
    	
    	system("cls");
    
    	cout << flight1 << endl;
    thats what i have so far, any idea why it won't work

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Quote Originally Posted by chris285
    any idea why it won't work
    No... You've given us WAY to little to work with. Is one of those lines of code you gave the one that produces the error in question? I'll reach deeeeeeeep into right-field and say... perhaps the flight1 object is causing the problem. It would help to see the full description of your CFunctions class.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    The example code you have provided is very anemic.. nothing more than an outline of a couple of functions, a Printall( ) function with a missing } curley brace.. and that's about it. Based on this lack of information, I am going to take a guess at your problem. Based on this tidbit of information:
    which has a set of array's for flights
    I am going to make the assumption that flight1 is an array of "flights". If this is the case, then this is your problem:
    Code:
    cout << flight1 << endl;  //thou shalt not attempt to cout an entire array 
                              //by cout'ing the array pointer to the first element
    Instead, try looping through your array, cout'ing one element at a time:
    Code:
    for(int i=0, i<arraylength, i++)
    
         cout << flight1[i];

    However, based on this information:
    it says undelcared identifier.
    you may still have an unresolved issue with perhaps.. a variable declaration.
    Last edited by The Brain; 04-20-2005 at 11:21 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    I believe the hint is... give more code...
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Just an odd sort of note, the fstream header is included when you include iostream.

    Also, I would suggest using a more standardized function than System().

    Code:
    cout << flight1 << endl;
    Should be this, because if you use <iostream> you'll need to either use the std namespace with a
    Code:
    using namespace std;
    directive at some point in your code, or resolve the namespace via scope-resolution operator ::
    Code:
    std::cout << flight1 << std::endl;
    That's without the above suggestion to not print out the memory-address of flight1 of course ^_^
    Last edited by Tronic; 04-20-2005 at 02:58 PM.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  6. #6
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Ha...I'm betting Tronic's solution works; the namespace thing is probably preventing cout and endl from resolving. It's funny that you guys could guess and come up with the solution to such an ill-defined problem.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    84
    ok this is the flights header file

    Code:
    // flights.h: interface for the Cflights class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #if !defined(AFX_FLIGHTS_H__99FAD8A2_A2AC_4D7A_B388_85DAB40490E0__INCLUDED_)
    #define AFX_FLIGHTS_H__99FAD8A2_A2AC_4D7A_B388_85DAB40490E0__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    class Cflights  
    {
    public:
    	Cflights();
    	virtual ~Cflights();
    	int assignflight();
    
    	char flight1[57];
    	char flight2[57];
    	char flight3[57];
    	char flight4[57];
    	char flight5[57];
    	char flight6[57];
    	char flight7[57];
    	char flight8[57];
    	char flight9[57];
    	char flight10[57];
    	char flight11[57];
    	char flight12[57];
    	char flight13[57];
    	char flight14[57];
    	char flight15[57];
    	char flight16[57];
    	char flight17[57];
    	char flight18[57];
    	char flight19[57];
    	char flight20[57];
    	char flight21[57];
    	char flight22[57];
    
    };
    and now i get the error code saying cout ambigious symbol

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    >> Just an odd sort of note, the fstream header is included when you include iostream.
    That is not correct. If your compiler does it you should definitely not rely on it happening.

    >> #include <iostream>
    >> #include <fstream.h>
    Don't mix old and new style headers. Use <iostream> and <fstream>. That might just get rid of your ambiguous symbol error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. yet another forward declaration problem.
    By sloppy_coder in forum C++ Programming
    Replies: 2
    Last Post: 12-12-2005, 02:59 AM
  3. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 03:09 PM

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