compiler error C2064

This is a discussion on compiler error C2064 within the C++ Programming forums, part of the General Programming Boards category; hey can anyone help me about this error. The error is in bold . Code: #include <iostream> #include <conio.h> using ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    14

    compiler error C2064

    hey
    can anyone help me about this error.
    The error is in bold.

    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    char 	const BLANK = ' ';	//constant: symbols used for the drawing (some could be local)
    char	const LEAF = '#';
    char	const WOOD = '|';
    char    const EOL = '\n';	
    int 	height;					//height of the tree
    int		branchLines;
    
    int main()
    {
    	void drawATrunk();
    	void drawBranches();
    	cout << "\nEnter the height of tree: ";
    	cin >>height;
    	if (height > 4)
    	{
    		drawBranches();
    	}
    	
    	while(!_kbhit());
    	return 0;
    }
    
    void drawBranches()
    {
    	void drawABranch();
    	for (branchLines(1); branchLines <= height-2; ++branchLines)
    	{	
    		drawABranch();
    	}
    }
    
    void drawABranch()
    {
    	for (int spaces(1); spaces <= (height-2)-branchLines; ++spaces)
    	{
    		cout << BLANK;
    	}
    	for (int leaves(1); leaves <= (branchLines*2)-1; ++leaves)
    	{
    		cout << LEAF;
    	}
    }
    
    void drawATrunk()
    {
    	int trunkLine;
    	trunkLine = 1;
    	while ( trunkLine <= 2) // for each line in the truck
    	{
    		for ( int spaces(1); spaces <= (height - 3); ++spaces) 	//draw the spaces on the left
    		{
    			cout << BLANK;
    	    }
    		cout << WOOD;			//draw the truck
    		cout << EOL	;		//go to next line
    		++trunkLine ;
    	}
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Not sure what C2064 says, but you cannot initialize an already-declared variable, you must assign to it; make it branchLines = 1.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    14

    Wink

    thanks. I didn't mention it.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    term does not evaluate to a function taking 'number' arguments
    In other words, it thinks it's a function. I'd avoid () with built-in types and just use =.
    Also, function prototypes goes into the header or at the start of the source file, not inside your functions.
    It's typically easier to read "const char" rather than "char const" - just a suggestion.
    And avoid global variables - make them local and pass them as arguments if need be.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Quote Originally Posted by Elysia View Post
    In other words, it thinks it's a function. I'd avoid () with built-in types and just use =.
    Also, function prototypes goes into the header or at the start of the source file, not inside your functions.
    It's typically easier to read "const char" rather than "char const" - just a suggestion.
    And avoid global variables - make them local and pass them as arguments if need be.
    Good suggestions, except -- function prototypes don't have to be global. Most of the time they are made global, but I can think of at least one book which used local function prototypes as a matter of course.

    I might also add that conio.h is non-standard and you should avoid it if possible.

    Code:
    char    const EOL = '\n';
    You probably don't need that constant . . . '\n' is generally accepted for printing newlines . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    > function prototypes don't have to be global. Most of the time they are made global, but I can think of at least one
    > book which used local function prototypes as a matter of course.

    Just out of curiosity, since local functions (functions defined inside other functions) currently aren't allowed in C/C++, what would be the advantage of local prototypes?

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    scoping, I guess.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    After reading this

    http://www.dcs.bbk.ac.uk/~roger/cpp/week5.htm

    I realized that a function could be defined in one source file, and then prototyped, locally, in another, which would be useful in limiting the scope in the second file. That's good to know.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    But how would that be used in a real program? You'd have header files and stuff.

  10. #10
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by robatino View Post
    After reading this

    http://www.dcs.bbk.ac.uk/~roger/cpp/week5.htm

    I realized that a function could be defined in one source file, and then prototyped, locally, in another, which would be useful in limiting the scope in the second file. That's good to know.
    In most cases - if you want to make function local to some source file - you implemt it in this source file as static.

    If you start adding function prototypes to 2-3 source file to make it visible only in these files - you are asking for troubles - when function prototype is changed and you forgot to update all the prototypes arond the code
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    >> In most cases - if you want to make function local to some source file - you implemt it in this source file as static.

    Just an FYI: Use an unnamed namespace instead of static. That use of static has been deprecated.

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Using global variables for just loops is bad, really bad.

    branchlines should be a local variable, and height should be passed as a parameter.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by dwks View Post
    Good suggestions, except -- function prototypes don't have to be global. Most of the time they are made global, but I can think of at least one book which used local function prototypes as a matter of course.
    But then we'll start to question if local prototypes are really a good idea.
    As was mentioned, all functions are global in nature, and to limit them from being extern, you can use static to limit it to internal linkage. Prototypes should, regardless, be stored in header files.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I just mentioned local prototypes because Elysia's post made it sound like you had to use global prototypes. (In which case the OP might have been wondering why it even compiled . . . .) All of Elysia's other points had "avoid" or "typically", except for the prototype one.
    In other words, it thinks it's a function. I'd avoid () with built-in types and just use =.
    Also, function prototypes goes into the header or at the start of the source file, not inside your functions.
    It's typically easier to read "const char" rather than "char const" - just a suggestion.
    And avoid global variables - make them local and pass them as arguments if need be.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 05:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 10:28 AM

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