error C2371: 'LineCollection' : redefinition; different basic types

S

Samant.Trupti

Hi,

I am getting this error.
error C2371: 'LineCollection' : redefinition; different basic types

I have 'LineCollection' defined in two header files in one project
Like
"typedef std::vector<line> LineCollection;"

But both of the header file not dependant on each other, they are
separate.
Why I am still getting that error?

How should I solve this problem? Should I just change the name?
Thanks
Trupti
 
M

mlimber

I am getting this error.
  error C2371: 'LineCollection' : redefinition; different basic types

I have 'LineCollection' defined in two header files in one project
Like
"typedef std::vector<line> LineCollection;"

But both of the header file not dependant on each other, they are
separate.
Why I am still getting that error?

How should I solve this problem? Should I just change the name?

No idea. See this FAQ on asking questions about code that doesn't
work:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

In brief, boil it down to a minimal but complete sample that
demonstrates the problem, then post it here.

Cheers! --M
 
S

Samant.Trupti

Ok I will try to write minimal code.
I have a project called "FileUtil"
It has two header files and 2 cpp files called
1. FileCompare.h and FileCompare.cpp
2. Compare.h and Compare.cpp

FileCompare.h
//Some Includes "Doesnot inclide compare.h"
typedef std::vector<line> LineCollection;
typedef LineCollection::iterator LineCollectionIter;

class FileCompare
{
....
LineCollection compFileMap;
LineCollection baseFileMap;
....
};

Compare.h
//Some Includes "Doesnot inclide FileCompare.h"
typedef std::vector<line> LineCollection;
typedef LineCollection::iterator LineCollectionIter;

class Compare
{
....
LineCollection m_baseLines;
LineCollection m_compLines;
....
};

Now I am getting error C2371: 'LineCollection' : redefinition;
different basic types.
I know that they are defined twice. I don't know why since two header
files are independant on each other.
Please let me know if this is enough to expalin the problem?
Thanks
Trupti
 
R

red floyd

Ok I will try to write minimal code.
I have a project called "FileUtil"
It has two header files and 2 cpp files called
1. FileCompare.h and FileCompare.cpp
2. Compare.h and Compare.cpp

FileCompare.h
//Some Includes "Doesnot inclide compare.h"
typedef std::vector<line> LineCollection;
typedef LineCollection::iterator LineCollectionIter;

class FileCompare
{
...
        LineCollection compFileMap;
        LineCollection baseFileMap;
...

};

Compare.h
//Some Includes "Doesnot inclide FileCompare.h"
typedef std::vector<line> LineCollection;
typedef LineCollection::iterator LineCollectionIter;

class Compare
{
...
        LineCollection m_baseLines;
        LineCollection m_compLines;
...

};

Now I am getting error C2371: 'LineCollection' : redefinition;
different basic types.
I know that they are defined twice.  I don't know why since two header
files are independant on each other.
Please let me know if this is enough to expalin the problem?


No. You *still* haven't followed the 5.8 recommentations. Post the
minimum *COMPILEABLE* code that exhibits the behavior in question.
 
J

James Kanze

Ok I will try to write minimal code.
I have a project called "FileUtil"
It has two header files and 2 cpp files called
1. FileCompare.h and FileCompare.cpp
2. Compare.h and Compare.cpp
FileCompare.h
//Some Includes "Doesnot inclide compare.h"
typedef std::vector<line> LineCollection;
typedef LineCollection::iterator LineCollectionIter;
class FileCompare
{
...
LineCollection compFileMap;
LineCollection baseFileMap;
...
};
Compare.h
//Some Includes "Doesnot inclide FileCompare.h"
typedef std::vector<line> LineCollection;
typedef LineCollection::iterator LineCollectionIter;
class Compare
{
...
LineCollection m_baseLines;
LineCollection m_compLines;
...
};
Now I am getting error C2371: 'LineCollection' : redefinition;
different basic types.
I know that they are defined twice. I don't know why since two header
files are independant on each other.

1. As others have pointed out: you haven't posted enough for us
to reproduce the problem, so anything we say is just a
guess.

2. What is "line"? You're allowed multiple typedef's, even in
the same translation unit, as long as they resolve to the
same thing. Your error message strongly suggests that you
have different definitions of "line", which will lead to no
end of problems.

3. FileCompare.h may not include Compare.h, and vice versa, but
logically, you have to expect some client code to include
both of them. In which case, if "line" is defined
differently in the two headers, you'll get a problem at
compile time. (Otherwise, the problems won't appear until
link time, or possibly even runtime.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top