473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Definition and Redefinition Errors in C++ Program

All,

Could someone help me with some errors. I am getting a Redefinition of 'class ClassNameHere' error in my .cpp file. Then, the header file that goes along with it has a error: previous definition of 'class ClassNameHere'. Does anyone know what this is and how to solve it? I can not seem to figure it out?

Thanks for any help you can provide-- CTYD
Feb 8 '08 #1
4 12333
sicarie
4,677 Expert Mod 4TB
You'll have to post your code to be sure, but it sounds like you have a duplicate constructor declaration (two places where you make the same declaration that takes the same arguments).
Feb 8 '08 #2
I figured it out after you pointed me in the right direction. I had each file starting with class ClassName. I should only have that line of code in the header section and not the definition file. I do appreciate your help with this....Thank You Sicaire- CTYD
Feb 8 '08 #3
hdanw
61
Every time I've had this problem it is with a definition in an hpp include file.

Definition, not declaration.

If you include the same file twice, directly or indirectly then you have effectively typed everything into the same file twice.

Try using the once keyword. This instructs the compiler to include the file once and no more.
Expand|Select|Wrap|Line Numbers
  1. // header.h
  2. #pragma once
  3. ....
  4.  
or use code like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef SomeLabel 
  3. #define SomeLabel
  4.  
  5. (.. Insert code here ..)
  6.  
  7. #endif
  8.  
  9.  
if the file has been included then "SomeLabel" is defined and the code is skipped.
Feb 8 '08 #4
sicarie
4,677 Expert Mod 4TB

Definition, not declaration.

Try using the once keyword. This instructs the compiler to include the file once and no more.
Expand|Select|Wrap|Line Numbers
  1. // header.h
  2. #pragma once
  3. ....
  4.  
or use code like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef SomeLabel 
  3. #define SomeLabel
  4.  
  5. (.. Insert code here ..)
  6.  
  7. #endif
  8.  
  9.  
if the file has been included then "SomeLabel" is defined and the code is skipped.
Ah, good catch, and good remediation. Thanks, hdanw.
Feb 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: john hrdo | last post by:
Hey, This might well be a naive question, please be patient. Is it possible to compile a C program including two libraries lib1 and lib2 which have both a function with same name, e.g....
2
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0...
4
by: junaidnaseer | last post by:
Hi ! I am facing a problem that I have defined a function which when called in the same file generates an error as follows; " visual c error C2371 redefinition basic types see...
2
by: Robbie Hatley | last post by:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote: > Robbie Hatley wrote: > > > > I ran into a problem a few days ago when I added a couple of > > template functions to one of my personal...
1
by: Alex | last post by:
Hello all, I have a very stupid problem that is driving me crazy...so plz if anyone ever saw this, I would like him to help me :) I have static MFC application in MSVC++ 6.0 (named Example)....
2
by: Mohammad Omer | last post by:
Hi, i am developing an application which uses WAB API's, for doing all this i am using vs2k5. I have wab.h header file included in my project to use WAB api's but after compilation one error...
4
by: urkel | last post by:
Hello everybody, I am getting bogged-down by these errors troubling me for the last few days I am writing a C program with a main and several user-defined functions. One of the user-defined...
3
by: Antonio Rivas | last post by:
Hello all. I've got a problem of multiple definition in a program that at first glance looks correct (I won't type the whole code, just the relevant one and as examples since seems is a linkage...
7
by: sh.vipin | last post by:
/* Sample code*/ #include <stdio.h> int a; //line # 3 int a; //line # 4 int main (int argc, char *argv){ printf("a is %d",a); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.