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

  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
    39,660
    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.

  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
    39,660
    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.

  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, 05: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, 11:49 AM