Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

another problem...

Status
Not open for further replies.

A1METALHEAD

Programmer
May 21, 2004
76
US
i am using visual c++ 6 to create a text adventure game. i have multipal headers and most have corasponding source files. one of the headers that dont is a header that i include in all cpp files. it has all the includs(like iostream and windows.h). the other is a header that just holds functions. i cant seem to include that function header in any file, or it will say that all the functions are already defined! is there anyway to go around this?

thanks,
~metalhead
 
Don't put function implimentations in the .h file. You should put ALL the implimentations in cpp files and this problem will go away. When you #include the same header different places and have the implimentation in the header, the compiler thinks you are redefining the function, as it sees the implimentation of a function that is already implimented.
 
THANKS! that fixed it, but now whenever i try to declare a linkedlist (that was what i was making) and then try to call any function with it, it will tell me that:
: error C2228: left of '.addNode' must have class/struct/union type
whats that mean?
 
> : error C2228: left of '.addNode' must have class/struct/union type
it probably means you have a pointer, and you should be writing
Code:
something->addNode

--
 
> whats that mean?

It means exactly what it sounds like.

You're saying
Code:
something.addNode()
in your program, and [tt]something[/tt] isn't a class, struct, or union, so the dot notation is meaningless.

What was your version of [tt]something[/tt] declared as?
 
as a linked list that has addNode(t*,y*) in it.

i know that there is somthing called a map that you can use a key to get an object:
map<x,y>
but i dont know how to use it! could somone tell me how to? and if there is a map that can use two keys to get the same object?
 
>but i dont know how to use it

Example:
Code:
#include <map>
#include <string>

// Defining a map where the key is a string 
// the value is an int
typedef std::map<std::string,int> > MyMap;

...
{
  MyMap m;
  m.insert(MyMap::value_type("Foo",42));
  m["Bar"] = 66;
  
  cout << m["Foo") << endl;

  if (m.find("Fnurt") != m.end())
  { } // Found "Fnurt"
  else
  { } // "Fnurt" not found 
}

>and if there is a map that can use two keys to get the same object?

Not unless you let the value part of the map be a pointers to the same instance. It's a bit tricky though.

/Per

&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top