What is error, kindly solve the issue and make me know my fault

This is a discussion on What is error, kindly solve the issue and make me know my fault within the C++ Programming forums, part of the General Programming Boards category; I have two files 1.dfa.hpp and 2. test.cpp 1.dfa.hpp's content Code: #include<iostream> using namespace std; namespace DFASpace{ class dfa { ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    What is error, kindly solve the issue and make me know my fault

    I have two files
    1.dfa.hpp and 2. test.cpp

    1.dfa.hpp's content
    Code:
    #include<iostream>
    using namespace std;
    
    namespace DFASpace{
            class dfa       {
                    dfa(int n)      {
                            cout << "The value of n is: " << n << endl;
                    }
            };
    }
    2.test.cpp's content
    Code:
    #include "dfa.hpp"
    
    using DFASpace;
    
    int main(){
            dfa d = dfa(50);
            return 0;
    }
    Am getting errors when I compile as:
    Code:
    [kapil@localhost learn3]$ g++ test.cpp  
    test.cpp:3: error: expected nested-name-specifier before ‘DFASpace’
    test.cpp:3: error: namespace ‘DFASpace’ not allowed in using-declaration
    test.cpp: In function ‘int main()’:
    test.cpp:6: error: ‘dfa’ was not declared in this scope
    test.cpp:6: error: expected ‘;’ before ‘d’

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    The last line of your namespace in the header file also needs a ; perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    134

    No this is not correct

    I dont think a namespace is defined in such way!
    for your words, I include ; yet its not working!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    using namespace std;

    using DFASpace;

    Spot the difference?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    134
    if you are talking about test.cpp then ; is there,
    kindly make the necessary changes on the code which you feel is not correct, may be I am unable to spot what you are talking about!

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    19
    You're missing the keyword namespace.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    134
    Sorry to say that Salem is very confusing, thnks to ctrl_freak

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux file redirection buffering issue !!!!
    By AirSeb in forum Linux Programming
    Replies: 8
    Last Post: 03-14-2009, 06:32 PM
  2. Replies: 3
    Last Post: 11-16-2006, 04:23 AM
  3. make, gcc path issue.
    By moultano in forum Tech Board
    Replies: 2
    Last Post: 08-25-2006, 12:49 PM

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