Static Variable running init

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick

    #1

    Static Variable running init

    Hi

    I have a Problem with my static vector which I defined. I'm using LTIB
    Library looks like this:

    test.h

    class test
    {
    public:
    static lti:channel8 img
    }

    test.cpp

    include .....

    lti:channel8 test::img(int sizex,int sizey,(byte) 0)

    test::test()... ...


    void test::create()
    {
    sizex = 6
    sizey = 7
    lti:channel8 test::img(sizex ,sizey,0) //I get the size I need only here
    so how do I initialize it correct
    }

    Anyone has an idea.

    Thanks

    Patrick


  • Bob Hairgrove

    #2
    Re: Static Variable running init

    On Tue, 26 Oct 2004 10:46:39 +0200, "Patrick"
    <this.20.pako@s pamgourmet.com> wrote:
    [color=blue]
    >Hi
    >
    >I have a Problem with my static vector which I defined. I'm using LTIB
    >Library looks like this:
    >
    >test.h
    >
    >class test
    >{
    >public:
    >static lti:channel8 img[/color]

    Shouldn't this have two colons?

    [the rest snipped]

    --
    Bob Hairgrove
    NoSpamPlease@Ho me.com

    Comment

    • Catalin Pitis

      #3
      Re: Static Variable running init


      "Patrick" <this.20.pako@s pamgourmet.com> wrote in message
      news:cll2th$pod $1@home.itg.ti. com...[color=blue]
      > Hi
      >
      > I have a Problem with my static vector which I defined. I'm using LTIB
      > Library looks like this:
      >
      > test.h
      >
      > class test
      > {
      > public:
      > static lti:channel8 img
      > }
      >
      > test.cpp
      >
      > include .....
      >
      > lti:channel8 test::img(int sizex,int sizey,(byte) 0)
      >
      > test::test()... ...
      >
      >
      > void test::create()
      > {
      > sizex = 6
      > sizey = 7
      > lti:channel8 test::img(sizex ,sizey,0) //I get the size I need only here
      > so how do I initialize it correct
      > }
      >
      > Anyone has an idea.
      >
      > Thanks
      >
      > Patrick
      >[/color]

      You should define the static members and this should be done outside any
      method or function and in the same namespace as the class containing it.
      Take this statement outside the create method.

      lti::channel8 test::img(sizex ,sizey,0)


      And it should be lti::channel8 instead of lti:channel8

      Catalin


      Comment

      • Patrick

        #4
        Re: Static Variable running init

        Hi
        The Colons are not the Problem this is only a functional demonstration.
        The Problem is how do i init it correct so I get hte right contructor
        initialization. Because outside of my function I don't have the right
        values.

        Patrick

        "Bob Hairgrove" <invalid@bigfoo t.com> wrote in message
        news:eh4sn0pprb p8ov8kgo0h1hbhh r35sn58lq@4ax.c om...[color=blue]
        > On Tue, 26 Oct 2004 10:46:39 +0200, "Patrick"
        > <this.20.pako@s pamgourmet.com> wrote:
        >[color=green]
        > >Hi
        > >
        > >I have a Problem with my static vector which I defined. I'm using LTIB
        > >Library looks like this:
        > >
        > >test.h
        > >
        > >class test
        > >{
        > >public:
        > >static lti:channel8 img[/color]
        >
        > Shouldn't this have two colons?
        >
        > [the rest snipped]
        >
        > --
        > Bob Hairgrove
        > NoSpamPlease@Ho me.com[/color]


        Comment

        • Patrick

          #5
          Re: Static Variable running init

          [color=blue][color=green]
          > > I have a Problem with my static vector which I defined. I'm using LTIB
          > > Library looks like this:
          > >
          > > test.h
          > >
          > > class test
          > > {
          > > public:
          > > static lti::channel8 img
          > > }
          > >
          > > test.cpp
          > >
          > > include .....
          > >
          > > lti:channel8 test::img(int sizex,int sizey,(byte) 0)
          > >
          > > test::test()... ...
          > >
          > >
          > > void test::create()
          > > {
          > > sizex = 6
          > > sizey = 7
          > > lti:channel8 test::img(sizex ,sizey,0) //I get the size I need only[/color][/color]
          here[color=blue][color=green]
          > > so how do I initialize it correct
          > > }
          > >
          > > Anyone has an idea.
          > >
          > > Thanks
          > >
          > > Patrick
          > >[/color]
          >
          > You should define the static members and this should be done outside any
          > method or function and in the same namespace as the class containing it.
          > Take this statement outside the create method.
          >
          > lti::channel8 test::img(sizex ,sizey,0)
          >
          >
          > And it should be lti::channel8 instead of lti:channel8
          >
          > Catalin
          >[/color]

          Hi

          I already did that but I don't have the values of this variables outside of
          my create method.

          Patrick


          Comment

          • Ron Samuel Klatchko

            #6
            Re: Static Variable running init

            "Patrick" <this.20.pako@s pamgourmet.com> wrote in message news:<cll2th$po d$1@home.itg.ti .com>...[color=blue]
            > I have a Problem with my static vector which I defined. I'm using LTIB
            > Library looks like this:
            >
            > test.h
            >
            > class test
            > {
            > public:
            > static lti:channel8 img
            > }
            >
            > test.cpp
            >
            > include .....
            >
            > lti:channel8 test::img(int sizex,int sizey,(byte) 0)
            >
            > test::test()... ...
            >
            >
            > void test::create()
            > {
            > sizex = 6
            > sizey = 7
            > lti:channel8 test::img(sizex ,sizey,0) //I get the size I need only here
            > so how do I initialize it correct
            > }[/color]

            A class static variable will be constructed before main() executes. There
            is nothing you can do about that.

            So, if you don't have the necessary information to properly create the
            object until runtime, you have a couple of choices:

            1) Instead of having a static object, have a static pointer and new the
            object at runtime.

            2) If the type supports assignment, construct it with dummy values and then
            at runtime, assign an instance constructed with the real vaulues.

            Good luck,
            samuel

            Comment

            Working...