Find the answer to your Linux question:
Results 1 to 3 of 3
Sorry I am new to Linux, please help. I created a small project by using KDeveloper in FC2. It worked fine. But when I did the same thing in FC4, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    2

    Help!! Got compilation error in FC 4, but it was OK in FC2


    Sorry I am new to Linux, please help.

    I created a small project by using KDeveloper in FC2. It worked fine. But when I did the same thing in FC4, unless I change "m_x = 3" to "John<T>::m_x = 3", gcc 4.0.0 always give me a fatal error --- "error: m_x was not declared in this scope".


    #ifdef HAVE_CONFIG_H
    #include <config.h>
    #endif

    #include <iostream>
    #include <cstdlib>

    using namespace std;

    template <class T>
    class John
    {
    protected:
    int m_x;
    };

    template <class T>
    class Johnsonublic John <T>
    {
    public:
    void dothis();
    };

    template <class T>
    void Johnson<T>::dothis()
    {
    m_x = 3;
    cout << "x=" << m_x;
    }

    int main(int argc, char *argv[])
    {
    cout << "Hello, world!" << endl;

    Johnson<int> johnson1;
    johnson1.dothis();

    return EXIT_SUCCESS;
    }

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    It would seem that gcc4 has stricter rules when it comes to scope...I don't think there's much you can do about it...Is it simply a warning or a fatal error that aborts compilation?

  3. #3
    Just Joined!
    Join Date
    Sep 2005
    Posts
    2
    Thanks for the help.

    It is a fatal error ----- error: m_x was not declared in this scope

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •