Thread: shared library enum scope problem

  1. #1
    Registered User
    Join Date
    Aug 2016
    Posts
    1

    shared library enum scope problem

    I've been searching the web and cannot find an answer to this particular problem:

    Here is some code:

    geo::GreatCircleArc* gca = new geo::GreatCircleArc_Impl(LA, NYC, 0.0);
    gca->calculateArcLength(gca);
    gca->calculateArcLength(gca, NAUTICAL_MILES);

    The classes with namespace geo are from the shared library. The enum NAUTICAL_MILES is also from the shared library, defined in an H file. That H file also has a namespace of geo (but separate from where I declare classes).

    The IDE eclipse has no problem with this (no red squiggly line) when it's a clean build. When I build, I get the error 'NAUTICAL_MILES' was not declared in this scope. (and then the red squiggly line). It appears to be an issue with the linking I would think. When I try to use the namespace geo::, only the class members "pop up" as suggestions.

    I'm a java programmer trying to become as proficient in c++ as I am in java. This is why I depend on the hints and suggestions of the ide.

    Any ideas of what is going on here?
    The pure virtual class GreatCircleArc and its implementation GreatCircleArc_Impl are declared in separate folders but use the same namespace. I'm trying to replicate the concept of a java interface and its implementation.

    Any help would be appreciated.

  2. #2
    Guest
    Guest
    So you tried geo::NAUTICAL_MILES? The IDE might (for whatever reason) not be smart enough to suggest it, even though it's right.

    By the way, one thing Java programmers moving to C++ are prone to is to new everything. Unless your class is very large (e.g. containing an array), you should prefer plain:
    Code:
    geo::GreatCircleArc_Impl gca(LA, NYC, 0.0);
    // or
    auto gca = geo::GreatCircleArc_Impl(LA, NYC, 0.0);
    Last edited by Guest; 08-24-2016 at 06:01 AM.

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    And if you're going to use `new`, at least feed it to the constructor of a smart pointer, like std::unique_ptr.

    Adrian, that's a very astute observation though! I was heartbroken when I found out you couldn't explicitly put an object on the stack in Java. They also use the term "reference" wrong as well. So it makes sense that a Java programmer would go to `new` as the first thing.

    Also OP, C++11's constructor syntax supports curly braces as well so now you can do:
    Code:
    int x{1337};
    I like the curly brace syntax because it really visually pops with regards to what is being constructed vs what is being invoked.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by MutantJohn
    They also use the term "reference" wrong as well.
    No, they use it correctly
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by laserlight View Post
    No, they use it correctly
    Yeah, you're right.

    I had to google it and yeah, apparently C++ is the freak of programming community with the way it uses "references". To me, though, it just makes the most sense. But that's an entirely subjective kind of thing. It made learning Java a bit interesting to shift what references meant in a different context.

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    The odd thing about references in c++ is that it conflicts with the term "pass by reference", which does not necessarily mean pass by C++ reference. It just means to pass things indirectly, which can be done with a reference, but also with a pointer, or a smarter resource handle of some sort.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in changing shared library path in linux
    By remyasj in forum Linux Programming
    Replies: 3
    Last Post: 08-06-2009, 08:31 AM
  2. Shared library design problem
    By p1r0 in forum C++ Programming
    Replies: 9
    Last Post: 03-23-2009, 12:36 PM
  3. Problem calling external method from within a shared library
    By Major Tom in forum C++ Programming
    Replies: 0
    Last Post: 04-21-2007, 09:14 AM
  4. Problem with custom shared library
    By soothsayer in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 12:48 PM
  5. wxWidgets loading shared library problem
    By BobS0327 in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2006, 07:23 PM

Tags for this Thread