Jump to content

Whats going on?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
espdev-darkness

espdev-darkness

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Hey codecall, I'm working on another program this one is a greeter type program with some cool string analysis abilities. It its generating a linker error LNK2019 using Visual Studio. From what I can tell the error is coming from the main() function about an unkown character but I cannot find this character.


/*

	Greeter Program

*/

#include <iostream>

#include <string>

#include <vector>

#include <cstdlib>

#include <ctime>

#include <cctype>


using namespace std;


//Function Prototypes

string pickGreeterName(vector<string> &names);

string assessUserName(string &name);


int main()

{

	//Creating a name library for greeters

	vector<string> greeterNameLibrary;

	greeterNameLibrary.push_back("James");

	greeterNameLibrary.push_back("John");

	greeterNameLibrary.push_back("Robert");

	greeterNameLibrary.push_back("Mary");

	greeterNameLibrary.push_back("Patricia");

	greeterNameLibrary.push_back("Linda");


	//Variable Definition

	string greeterName = pickGreeterName(greeterNameLibrary);

	string userName;

	

	//Main Program

	cout << "Welcome! My name is " << greeterName << " and I will be your greeter in this instance." << endl;

	cout << "What is your name? ";

	cin >> userName;


	cout << assessUserName(userName);


	cin.get();

	return 0;

}


string pickName(vector<string> &names)

{

	srand(static_cast<unsigned int>(time(0)));

	return *(names.begin() + (rand() % names.size()));

}


string assessUserName(string &name)

{

	//Function Variables

	int capitalCounter = 0;

	int nonAlphabetCounter = 0;


	//String Analysis Loop

	for (int i = 0; (name.size() - 1); ++i)

	{

		if (isupper(name[i])) ++capitalCounter;

		if (isalpha(name[i])) ++nonAlphabetCounter;

	}


	//String Analysis Final

	if (++capitalCounter > ((double)name.size() / 2) && nonAlphabetCounter)

	{

		return "Why all the capitals, and what is with those weird characters?";

	}


	else if (++capitalCounter > ((double)name.size() / 2))

	{

		return "Why all the capitals?";

	}

	else if (nonAlphabetCounter)

	{

		return "What's with the strange characters?";

	}


	return "So what's up?";

}		



Thanks, I really want to continue this program and these errors are frustrating.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
"LNK2019" is an undefined reference error:
[Linker Error] undefined reference to `pickGreeterName(std::vector<std::string, std::allocator<std::string> >&)'
This is caused because you tell the compiler the function pickGreeterName() exists with a prototype, although it is not defined within your script when you call it. This is why the error happens at link-time, as the compiler assumes the prototype points to a function but the function does not exist.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
espdev-darkness

espdev-darkness

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Wow, I didn't notice that I must have changed the name of one of my functions without changing the prototype name. Thanks.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users