PDA

View Full Version : OT: C++ Help?



ShawnStovall
06-29-2007, 12:37 AM
// Ex7_12.cpp
// Using a static data member in a class
#include <iostream>
using std::cout;
using std::endl;

class CBox
{
public:
static int objectCount;

CBox(double lv, double bv = 1.0, double hv = 1.0)
{
cout << endl << "Constructor called.";
m_Length = lv;
m_Width = bv;
m_Height = hv;
objectCount++;
}

CBox()
{
cout << endl
<< "Default Constructor called.";
m_Length = m_Width = m_Height = 1.0;
objectCount++;
}

double Volume()
{
return m_Length*m_Width*m_Height;
}

int Compare(CBox xBox)
{
return this->Volume() > xBox.Volume();
}

private:
double m_Length;
double m_Width;
double m_Height;
};

int main()
{
CBox boxes[5];
CBox cigar(8.0, 5.0, 1.0);

cout << endl << endl
<< "Number of objects (through class) = "
<< CBox::objectCount;

cout << endl
<< "Number of objects (through object) = "
<< boxes[2].objectCount;

cout << endl;
return 0;
}

Could someone please help me with this? I'm getting a LINK error and don't know why(Visual Studio 2008 Beta 1 and 2005). Could someone help me spot what is going on?

dballesg
06-29-2007, 01:59 AM
Hi Shawn,

You need to declare and initialize the static members OUTSIDE the class as well.

Add the:


int CBox::objectCount = 0;

before your main and there you go! :)

Best regards,
David


// Ex7_12.cpp
// Using a static data member in a class
#include <iostream>
using std::cout;
using std::endl;

class CBox
{
public:

static int CBox::objectCount;

CBox(double lv, double bv = 1.0, double hv = 1.0)
{
cout << endl << "Constructor called.";
m_Length = lv;
m_Width = bv;
m_Height = hv;
objectCount++;
}

CBox()
{
cout << endl
<< "Default Constructor called.";
m_Length = m_Width = m_Height = 1.0;
objectCount++;
}

double Volume()
{
return m_Length*m_Width*m_Height;
}

int Compare(CBox xBox)
{
return this->Volume() > xBox.Volume();
}

private:
double m_Length;
double m_Width;
double m_Height;
};

// It is a static member so you need to declare it OUTSIDE the class
// and use the scope scope resolution operator to
// identify which class it belongs to
int CBox::objectCount = 0;

int main()
{
CBox boxes[5];
CBox cigar(8.0, 5.0, 1.0);

cout << endl << endl
<< "Number of objects (through class) = "
<< CBox::objectCount;

cout << endl
<< "Number of objects (through object) = "
<< boxes[2].objectCount;

cout << endl;
return 0;
}

/*
// boxccpp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
*/

ShawnStovall
06-29-2007, 02:28 AM
Ah!! Thanks, I missed that.:)

ShawnStovall
06-29-2007, 02:41 AM
By the way, what knowledge should I have before delving into the LightWave SDK(I'll be doing this later, don't know enough now).

dballesg
06-29-2007, 09:14 AM
Hi Shawn,

You pretend to use plain C? Or CPP with the SDK?

Are two different things! :)

But I will recommend you to read the SDK docs at least twice before you start writing any code. At least so you are familiar with all it's functions and what you will need for plugin creation.

Best regards,
David

ShawnStovall
06-29-2007, 10:01 AM
C++ of course!!:) I heard it is easy to understand C once you know C++, I have already learned all the non-object-oriented part of C++. Now for the OO part...:grumpy:

adamredwoods
06-29-2007, 12:03 PM
I don't think they ported the SDK over to C++ yet.

ShawnStovall
06-29-2007, 12:07 PM
I know, but I was hoping my understanding of C++ would help me understand the C in the SDK.

dballesg
06-29-2007, 12:19 PM
Hi SHawn,

Maybe your understanding of C++ will confuse you a bit when you read the SDK! :)

They talk about classes, but they do not mean C++ classes, they are talking about classes of plugins! :)

ShawnStovall
06-29-2007, 12:27 PM
Hmmm... thanks, I try to trudge through it...

ShawnStovall
07-01-2007, 11:58 PM
For thous of you that have developed plug-ins for LightWave using a high-level programming language, is there any specific math I need to learn or programming styles?

dballesg
07-02-2007, 12:48 AM
Hi Shawn,

The math involved depends a lot of the plugin you want to develop. A ray tracer for example will involve algebra and calculus. Mainly vectors and Matrices.

An exporter or importer from one type of file will involve less maths or simply pointer math.

Best regards,
David

ShawnStovall
07-02-2007, 12:50 AM
I'm wanting to develop some modeler plug-ins and am wondering what I should learn for that.

Matt
07-02-2007, 05:15 AM
I sooooooooooo want to get back into programming, but I fear my brain is too old to re-learn it all again!

Tempted to d/l one of the free MS packages and have a go!

But what language would YOU learn now if you had to do it all again?

Lightwolf
07-02-2007, 05:24 AM
But what language would YOU learn now if you had to do it all again?
C++

Fairly high level, widely used, performs well. Not something I'd learn for the sake of learning ro program, but for the sake of writing programs (if you know what I mean - it isn't the most concise to pick up - but very "real world").
That is, if you want to stay cross platform or hook up to other apps.
If you want to code stuff that lives on its own, there's more options (Java, or depending on the platform C#, Obj-C, etc...)

Cheers,
Mike

dballesg
07-02-2007, 09:18 AM
I'm wanting to develop some modeler plug-ins and am wondering what I should learn for that.

You are going to need much more vector and matrices than calculus for those! :)

Why do you not have a look to the modeler samples that came with the SDK of Lightwave?

Best regards,
David