What the code does: accept a stock ticker eg AAPL as text input. It assigns it a number if it hasn't already been assigned a number. Then returns the number associated with that ticker. Part of a larger program.

The code for int gethandle worked fine when it was in the main program. The main CPP file got too large so this was moved over to a separate .CPP file.

It stops building below the line

int gethandle(string hdlText)


And says
error c2447: '{' missing function header (old style formal list?)


I know this subject has come up before. I browsed through numerous other old threads. Usually the problem was a semicolon where there didn't need to be one. I don't see that anywhere in this program.

#include <iostream>
#include <string>
using namespace std
#include <fstream>
#include <comdef.h>  // for _bstr_t
#include <string>
#include "stdAfx.h"


int gethandle(string hdlText)

{    //   <<<<--------------------------   This is where the problem is
	static string tkr[1000];
	static int lastCache;
	if (hdlText == tkr[lastCache]) 
	{
	return lastCache;
	}

	int count;
	for (count =1 ; count < 1000; count++)
	{
		if (tkr[count] == hdlText) 
		{
			lastCache = count;
			return count;
		}

	}
		for (count =1; count<1000; count++)
	{
		if (tkr[count] == "") 
		{
			tkr[count] = hdlText;
			lastCache = count;
			return count;
		}

	}

	return -1000; // debug program elsewhere. We should not run out of handles
}

Recommended Answers

All 5 Replies

You're missing a semicolon after using namespace std; If that's just a typo, look in stdAfx.h to make sure you aren't missing a semicolon in there instead.

Welcome to Daniweb!
Please use code-tags around the code that you post.

I don't know where you saw that problems can occur when you have too many semi-colons. Usually, it is the other way around. Many stupid little compile errors can be solved with adding semi-colons. Usually, it is safer to add a semi-colon after each closing }. Also, you have to leave some empty lines at the end of any header or cpp files. Finally, you should always put the statement "using namespace std;" and any other "using namespace XXX;" statements after you have included all headers (not in the middle of the includes as you did). And also, you should never have "using namespace XXX;" statements inside a header file. So, a revision of your code, with these changes, gives this (assuming this is a cpp file):

#include <iostream>
#include <string>
#include <fstream>
#include <comdef.h> // for _bstr_t
#include <string>
#include "stdAfx.h" // note: using old C libraries will sometimes cause these kind of errors you are experiencing.

using namespace std; //put using namespace statements after the #includes above.

int gethandle(string hdlText)
{ // <<<<-------------------------- This is where the problem is... NOT REALLY!
  static string tkr[1000];
  static int lastCache;
  if (hdlText == tkr[lastCache])
  {
    return lastCache;
  };

  int count;
  for (count =1 ; count < 1000; count++)
  {
    if (tkr[count] == hdlText)
    {
      lastCache = count;
      return count;
    };

  };
  for (count =1; count<1000; count++)
  {
    if (tkr[count] == "")
    {
      tkr[count] = hdlText;
      lastCache = count;
      return count;
    };

  };

  return -1000; // debug program elsewhere. We should not run out of handles
};

// a few empty lines here.

You're missing a semicolon after using namespace std; If that's just a typo, look in stdAfx.h to make sure you aren't missing a semicolon in there instead.

Thanks,
I added the semicolon after using namespace std; and it's still doing it. As for stdAfx.h it's a library that came with the compiler, not something I wrote, so I don't think stdAfx.h would be missing a semicolon anywhere. Or were you referring to the line that mentions stdAfx.h , was this line typed incorrectly? I didn't quite understand the second part of this answer.

Note that if you are using precompiled header stdafx.h must be the very first include file in the *.cpp file. If you are not using precompiled headers then it won't matter one way or the other where it is, and you could even delete it altogether if there is nothing useful in it.

No, I was thinking maybe something within the header if you had modified it. See if Mike's suggestion of moving things around works, then we can go from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.