Results 1 to 8 of 8

Thread: How to compile a project with two classes with same name in different namespaces?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to compile a project with two classes with same name in different namespaces?

    Quote Originally Posted by bytelivre View Post
    this becomes inelegant.
    If you don't mind my opinion. If you do, just don't read it ;-)

    What you suggest is extremely ugly. I guess you are used to write code in Java?
    I prefer to give all my classes a unique name and in their separate files. I do use sub directories to organise the code a little bit. But I have never had a use for namespaces, how complex my program might be. In fact, I think it confuses people when they need to read a lot of complex code.

    Edit: I have looked at code like Open Office etc... Ohh my dear sweet deity, that is beyond insane, especially the directory structures.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to compile a project with two classes with same name in different namespaces?

    If you've sequestered your classes within different namespaces, you won't get any name collisions unless you've managed to do something wrong. The most common error is excessive or inappropriate use of the 'using' statement, which can strip off namespaces completely and undo the protection they offer. Please post the offending code and the error messages you're receiving.

    Also, I agree with tbscope: it looks like you're trying to emulate Java, rather than use good coding practices. Excessive namespace depth is not necessary in C++ and only serves to make code harder to read. If you need to organize classes, do so with libraries. If you're getting name collisions within your own project, that's a design problem, not a namespace problem.

  3. #3
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to compile a project with two classes with same name in different namespaces?

    Excessive namespace depth is not necessary in C++ and only serves to make code harder to read
    I'd disagree with you, use of namespaces is absolutely clear in C++. Sometimes you just need to give the classes same names. And sometimes you use other's code and there's no chance to "rename" it for your use. And, also, if you deliver a code to somebody, they would like to keep a chance to give their classes any names.

Similar Threads

  1. Project suddenly doesn't compile
    By vieraci in forum Qt Programming
    Replies: 16
    Last Post: 7th June 2016, 07:12
  2. help,who could help me to compile qt project
    By derekli in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2014, 15:27
  3. Replies: 7
    Last Post: 6th May 2010, 09:52
  4. Project compile problems
    By MarkoSan in forum Qt Programming
    Replies: 7
    Last Post: 15th October 2009, 12:54
  5. qmake: add to project but do not compile
    By jesse in forum Newbie
    Replies: 2
    Last Post: 8th November 2007, 16:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.