LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2005, 01:30 PM   #1
esrrms
LQ Newbie
 
Registered: May 2005
Posts: 7

Rep: Reputation: 0
c++ array init help


Could someone tell me why this throws an error? I thought you could initialize an array like this.

light.hh
Code:
#ifndef _LIGHT_HH
#define _LIGHT_HH

#include <GL/gl.h>

class light
{
public:
  light(GLenum);

private:
  GLenum m_lightNum;
  GLfloat m_ambient[4];
  GLfloat m_diffuse[4];
  GLfloat m_specular[4];
  GLfloat m_position[4];
  GLfloat m_spotDirection[3];
  GLfloat m_spotExponent;
  GLfloat m_spotCutOff;
  GLfloat m_constantAttenuation;
  GLfloat m_linearAttenuation;
  GLfloat m_quadraticAttenuation;
};

#endif // _LIGHT_HH
light.cc
Code:
#include "light.hh"

light::light(GLenum p_lightNum)
  : m_lightNum(p_lightNum)
    , m_ambient(0.0, 0.0, 0.0, 1.0) // <----- this throws the error.
{
}
 
Old 05-16-2005, 01:40 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
try
Code:
m_ambient = {0.0, 0.0, 0.0, 1.0};
 
Old 05-16-2005, 01:43 PM   #3
esrrms
LQ Newbie
 
Registered: May 2005
Posts: 7

Original Poster
Rep: Reputation: 0
nope, that throws an error too.
 
Old 05-16-2005, 01:56 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Oh.. right... I'm an idiot... only works if you do init like that on declaration.

Works:
Code:
char array[4] = {'a', 'b', 'c', 'd'};
Doesn't work:
Code:
char array[4];
array = {'a','b','c','d');
 
Old 05-16-2005, 02:27 PM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You've got a couple of options:

Code:
light::light(GLenum p_lightNum)
  : m_lightNum(p_lightNum)
{
    m_ambient[0] = 0.0;
    m_ambient[1] = 0.0;
    m_ambient[2] = 0.0;
    m_ambient[3] = 1.0;
}
Or:

Code:
light::light(GLenum p_lightNum)
  : m_lightNum(p_lightNum)
{
    GLfloat temp[] = {0.0, 0.0, 0.0, 1.0};
    
    // Could do the following with something like memcpy too
    for (int c=0;c<4;c++) m_ambient[c] = temp[c];
}
 
Old 05-16-2005, 07:06 PM   #6
esrrms
LQ Newbie
 
Registered: May 2005
Posts: 7

Original Poster
Rep: Reputation: 0
thanks guys, appreciate it.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redhat linux9.0:System hangs,if gives init 3 or init 4 Sailaja Reddy Linux - Newbie 4 09-16-2004 03:19 AM
Kernal Panic: No init found. Try passing init= option to kernel raees Linux - General 12 03-18-2004 11:10 PM
PERL: Size of an array of an Array inspleak Programming 2 03-10-2004 02:24 PM
error: No init found. Try passing the init= option to the Kernel neylitalo Linux - Laptop and Netbook 3 01-22-2004 09:34 PM
error "Kernel panic: No init found. Try passing init= option Anauj0101 Linux - Newbie 3 05-06-2003 10:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration