Simple Class definition

This is a discussion on Simple Class definition within the C++ Programming forums, part of the General Programming Boards category; I decided to relearn some of the stuff i should already know. I am trying to make a class, and ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    80

    Simple Class definition

    I decided to relearn some of the stuff i should already know.
    I am trying to make a class, and a member function that displays a simple character.

    here is the code that i have split into 3 files
    the error i get is something like "Multiple definitions of info::display"

    can anyone see what the error is?

    Code:
    class info
    {
     public:
                 
        void display();
         
      //   int length();
         
      //   char concatenate();
         
      //   char substring();
         
         
         private:
         char s;
         
         };

    Code:
    #include "4dot6header.h"
    
    
    void info::display()
    {
    
        
    }

    Code:
    #include<iostream>
    #include "4dot6.cpp"
    using namespace std;
    
    int main()
    {
        info a;
        a.display();
        
    
    
    system("pause");
    return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    Instead of including "4dot6.cpp", include "4dot6header.h". "4dot6header.h" should also have header inclusion guards.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    80
    Im not understanding what u mean. can u right that in the code?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    Code:
    #ifndef INCLUDED_4DOT6HEADER_H_
    #define INCLUDED_4DOT6HEADER_H_
    
    class info
    {
        public:
    
        void display();
    
        //   int length();
    
        //   char concatenate();
    
        //   char substring();
    
    private:
        char s;
    
    };
    
    #endif
    Code:
    #include <iostream>
    #include "4dot6header.h"
    using namespace std;
    
    int main()
    {
        info a;
        a.display();
    
        system("pause");
        return 0;
    }
    Incidentally, system() is found in <cstdlib>, not <iostream>.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  2. class definition Q
    By scipitam in forum C++ Programming
    Replies: 8
    Last Post: 10-24-2006, 09:06 PM
  3. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 10:33 AM
  4. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21