Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Static Variable running init

Reply
Thread Tools

Static Variable running init

 
 
Patrick
Guest
Posts: n/a
 
      10-26-2004
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


 
Reply With Quote
 
 
 
 
Bob Hairgrove
Guest
Posts: n/a
 
      10-26-2004
On Tue, 26 Oct 2004 10:46:39 +0200, "Patrick"
<(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Catalin Pitis
Guest
Posts: n/a
 
      10-26-2004

"Patrick" <(E-Mail Removed)> wrote in message
news:cll2th$pod$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Patrick
Guest
Posts: n/a
 
      10-26-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 26 Oct 2004 10:46:39 +0200, "Patrick"
> <(E-Mail Removed)> 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
> (E-Mail Removed)



 
Reply With Quote
 
Patrick
Guest
Posts: n/a
 
      10-26-2004

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


 
Reply With Quote
 
Ron Samuel Klatchko
Guest
Posts: n/a
 
      10-27-2004
"Patrick" <(E-Mail Removed)> wrote in message news:<cll2th$pod$(E-Mail Removed)>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
init of class members : mem(0) vs. mem() vs. not-init at all news.aon.at C++ 11 01-29-2011 07:30 PM
questions about object initialization, default-init and value-init Jess C++ 4 05-04-2007 02:47 AM
Sequence Order between Page Init and User Control Init Tony Cheng ASP .Net 1 02-24-2006 01:56 PM
Compiler/Linker Error undefined reference to 'std::ios_base::Init::Init[in-charge]() clusardi2k@aol.com C++ 1 08-18-2005 07:11 PM
How to Init static variable in Template naruto C++ 3 05-20-2004 02:05 AM



Advertisments