Static Variable running init

Discussion in 'C++' started by Patrick, Oct 26, 2004.

  1. Patrick

    Patrick Guest

    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
    Patrick, Oct 26, 2004
    #1
    1. Advertising

  2. On Tue, 26 Oct 2004 10:46:39 +0200, "Patrick"
    <> wrote:

    >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


    Shouldn't this have two colons?

    [the rest snipped]

    --
    Bob Hairgrove
    Bob Hairgrove, Oct 26, 2004
    #2
    1. Advertising

  3. "Patrick" <> wrote in message
    news:cll2th$pod$...
    > 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
    >


    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
    Catalin Pitis, Oct 26, 2004
    #3
  4. Patrick

    Patrick Guest

    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" <> wrote in message
    news:...
    > On Tue, 26 Oct 2004 10:46:39 +0200, "Patrick"
    > <> wrote:
    >
    > >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

    >
    > Shouldn't this have two colons?
    >
    > [the rest snipped]
    >
    > --
    > Bob Hairgrove
    >
    Patrick, Oct 26, 2004
    #4
  5. Patrick

    Patrick Guest


    > > 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
    > >

    >
    > 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
    >


    Hi

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

    Patrick
    Patrick, Oct 26, 2004
    #5
  6. "Patrick" <> wrote in message news:<cll2th$pod$>...
    > 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
    > }


    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
    Ron Samuel Klatchko, Oct 27, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Cheng
    Replies:
    1
    Views:
    8,205
    Juan T. Llibre
    Feb 24, 2006
  2. naruto
    Replies:
    3
    Views:
    428
    naruto
    May 20, 2004
  3. Replies:
    1
    Views:
    656
    Jules
    Aug 18, 2005
  4. Jess
    Replies:
    4
    Views:
    438
  5. news.aon.at
    Replies:
    11
    Views:
    640
    Ian Collins
    Jan 29, 2011
Loading...

Share This Page