473,395 Members | 1,466 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,395 software developers and data experts.

after assistance with Visual c++, multiple file redeclaration

Hi,

I am trying to compile my code from several small files, as it was getting unweildly in a large file.

I have simplified my problem somewhat, and if I could solve this example the rest may flow. (or I'll get into deeper water!) This is Visual c++ 2005 express edition.

file 1: aaa.hpp

Expand|Select|Wrap|Line Numbers
  1. #ifndef AAA_H
  2. #define AAA_H
  3. #pragma once
  4.  
  5. class aaa {
  6. public:
  7.     aaa(char *str);
  8.     void setFile(char *str );
  9.     int record_count() ;
  10. private:
  11.     char filename[256];    //  filename of the data file for the data
  12.     int numrecords;
  13. } ;
  14.  
  15. #endif
  16.  
  17.  
file 2: aaa.cpp

Expand|Select|Wrap|Line Numbers
  1. #include "aaa.hpp"
  2.  
  3. class aaa {
  4. public:
  5.     aaa(char *str) {
  6.         //  Constructor
  7.         std::cout << "\n\n----------\nData for:" << filename << "\n" ;
  8.     } ;
  9.     void setFile(char *str) {
  10.         strcpy_s( filename, str );  //  store main directory
  11.     } ;
  12.     int record_count() {
  13.         return numrecords ;
  14.     } ;
  15. private:
  16.     char filename[256];    //  filename of the data file for the data
  17.     int numrecords;
  18. } ;
  19.  
  20.  
When I select aaa.cpp in the IDE, right click and select compile I get:
Expand|Select|Wrap|Line Numbers
  1. Compiling...
  2. class aaa.cpp
  3. .\class aaa.cpp(17) : error C2011: 'aaa' : 'class' type redefinition
  4.  c:\documents and settings\fred\my documents\visual studio 2005\projects\testing classes\testing classes\aaa.hpp(5) : see declaration of 'aaa'

So far I have written my application nicely in a big file, and am referring to my books here at home to check on the content of the header file in case I have mucked up my definitions, but there is not a lot of info I can find to narrow it down.

Any assistance greatfully accepted,
Thanks,
Treegum
Nov 10 '06 #1
4 1965
more information.
to try an simpl
ify my code a bit, I removed the variousother #include from aaa.cpp. I seem to be able to get a relatively simple aaa.hpp working when I so the following:

Expand|Select|Wrap|Line Numbers
  1.  #ifndef AAA_H
  2. #define AAA_H
  3. #pragma once
  4. class aaa ;
  5. #endif
So I figure I am doing my declarations incorrectly, but as soon as I add the {} to put anything after the class name, I get the redefinition error.

thanks for any suggestions,
Treegum
Nov 10 '06 #2
Banfa
9,065 Expert Mod 8TB
file 2: aaa.cpp

Expand|Select|Wrap|Line Numbers
  1. #include "aaa.hpp"
  2.  
  3. class aaa {
  4. public:
  5.     aaa(char *str) {
  6.         //  Constructor
  7.         std::cout << "\n\n----------\nData for:" << filename << "\n" ;
  8.     } ;
  9.     void setFile(char *str) {
  10.         strcpy_s( filename, str );  //  store main directory
  11.     } ;
  12.     int record_count() {
  13.         return numrecords ;
  14.     } ;
  15. private:
  16.     char filename[256];    //  filename of the data file for the data
  17.     int numrecords;
  18. } ;
  19.  
  20.  
In this file you have redeclared class aaa

class aaa {

You just need to define it's member functions

Expand|Select|Wrap|Line Numbers
  1. #include "aaa.hpp"
  2.  
  3. aaa::aaa(char *str) {
  4.     //  Constructor
  5.     std::cout << "\n\n----------\nData for:" << filename << "\n" ;
  6. }
  7.  
  8. void aaa::setFile(char *str) {
  9.     strcpy_s( filename, str );  //  store main directory
  10. }
  11.  
  12. int aaa::record_count() {
  13.     return numrecords ;
  14. }
  15.  
Nov 10 '06 #3
Thanks for this... which is somewhere I got to before which gave me a different error, so I figured I was going in the wrong direction...?

file 1: aaa.hpp
Expand|Select|Wrap|Line Numbers
  1. #ifndef AAA_H
  2. #define AAA_H
  3. #pragma once
  4.  
  5. class aaa {
  6. public:
  7.     aaa(char *);
  8.     void setFile(char *);
  9.     int record_count() ;
  10. private:
  11.     char filename[256];    //  filename of the data file for the data
  12.     int numrecords;
  13. }
  14.  
  15. #endif
and file 2: aaa.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "aaa.hpp"
  2.  
  3.     aaa::aaa(char *str) {
  4.         //  Constructor
  5.         std::cout << "\n\n----------\nData for:" << filename << "\n" ;
  6.     } ;
  7.     void aaa::setFile(char *str) {
  8.         strcpy_s( filename, str );  //  store main directory
  9.     } ;
  10.     int aaa::record_count() {
  11.         return numrecords ;
  12.     } ;
however now I get another error...
Expand|Select|Wrap|Line Numbers
  1.  Compiling...
  2. class aaa.cpp
  3. c:\documents and settings\u448467\my documents\visual studio 2005\projects\testing classes\testing classes\aaa.hpp(11) : error C2071: 'aaa::filename' : illegal storage class
  4. .\class aaa.cpp(19) : error C2533: 'aaa::{ctor}' : constructors not allowed a return type
and if I compile it without 'aaa::aaa(){}', and just aaa(){}... ut I'll get to that shortly...
so, should I be using aaa::aaa(){} for a constructor, or aaa(){}?

Thanks,
treegum
Nov 11 '06 #4
Well thanks for the assistance banfa. I did a typo which resulted in my error in the last post. I am all good now, and your answer was quite correct (but I'm sure you knew that ;)

Cheers,
treegum
Nov 13 '06 #5

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

Similar topics

1
by: tread | last post by:
Objective: The primary table I loaded into MySql has 2.5 MM records: ID, Ticker, Date, Price; and all works well. My need is to write a QUERY to export outfile?) multiple text files. For example,...
1
by: Wendy Elizabeth | last post by:
Can you give me some suggestions of why the xml web service is not working? I have an xml web service that works in my visual studio. net 1.1 environment. I setup this project up for deployment...
2
by: SenthilVel | last post by:
HI all in my visual studio DOtnet . i am not able to open multiple cs files in the projects , its openings only one cs file at a time, can any one let me know, what setttings i must do in order...
2
by: mchamsters | last post by:
Just want to rant about something horrible that happened to me tonight. It was my first time using the new Visual C#. I started a new project, coding away continuously for about 6 hours. I saved...
4
by: Ravi Ambros Wallau | last post by:
Hi: We developed a set of ASP.NET Web Applications that never runs in stand-alone mode, but always inside a portal (Rainbow Portal). All modules are copied on that portal. My question is: load...
0
by: Massimiliano Polito | last post by:
It seems the option '/useenv' is no longer supported in in Microsoft Visual .NET 2005. If I run 'devenv /?' I get the following: ------------------------ Microsoft (R) Visual Studio Version...
3
by: silentcoast | last post by:
Alright im not sure why but im getting a "member function redeclaration not allowed" error when I to compile this simple program. main.cpp #include "main.h" CNetwork net; int main() {...
9
by: OWeb | last post by:
Javascript and recursing subfolders assistance ------------------------- I have this script that is a free extra download from SlideShowPro. It's a great script but I feel it needs to be...
7
by: Andrew Jocelyn | last post by:
Hi I'm running an ASP.NET web application under IIS. I'm inserting a cache object with a file based CacheDependency. I've noticed that when the file changes the Cache object is not always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.