Static Variable running init

P

Patrick

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
 
B

Bob Hairgrove

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

Catalin Pitis

Patrick said:
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
 
P

Patrick

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 said:
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]
 
P

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
 
R

Ron Samuel Klatchko

Patrick said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top