Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET properties won't compile 1

Status
Not open for further replies.

PlasmaZero

Programmer
Dec 6, 2002
13
US
Hi, I'm working on a project using some .NET things, like properties (get/set). However, visual studio .net is not recognizing the properties format and is giving me compile errors i.e. "syntax error: 'return'" and "unexpected tokens preceding ';'". I've included both system.dll and mscorlib.dll and used the (I believe) appropriate namespaces, and I can't figure out why VS.NET isn't recognizing the format. Here's one file (out of many of the project) that is getting the error.

#if !defined(TRACK)
#define TRACK

#using <system.dll>
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;

#include "seq.h"
#include "soundgen.h"

class Track : public Seq
{
public:
Track();
Track(SoundGen inst);
~Track();

double output_sample();

SoundGen Instrument {
get {
return instrument;
}
set {
instrument = value;
}
}

double Gain {
get {
return gain;
}
set {
gain = value;
}
}

// Note manip
void addNote(Note note);
void removeNote(int index);
void insertNote(int index, Note note);
Note getNote(int index);

private:
SoundGen instrument;
Notes notes;
double gain=1.0;
};

// Track Collection def
class Tracks : public CollectionBase
{
// Method implementation from the CollectionBase class
public void Add(Track track){
List.Add(track);
}

// Method implementation from the CollectionBase class
public void Remove(int index){
// Check to see if there is a Track at the supplied index.
if (index > Count - 1 || index < 0)
throw new Exception("Index out of bounds");
List.RemoveAt(index);
}

// Method implementation from the CollectionBase class
public void Insert(int index, Track track) {
List.Insert(index, track);
}

// Method implementation from the CollectionBase class
public Track Item(int Index) {
return (Track) List[Index];
}

};

#endif // TRACK

Any ideas?
Thanks,
Tom
 
look in class Tracks, I don't see where you declared List what you use in function Item. BTW, if you sompile in .NET mode, you should declare your classes as __gc.

Ion Filipski
1c.bmp
 
The Get/Set properties you have tried to implement are for the C# class properties. You need to create the C++ .NET version.

This involves defining get_PropertyName and set_PropertyName. Then your class definition will appear to have a property call "PropertyName".

Here is some sample code:

__gc class TestClass
{
public:
TestClass() {}
__property int get_Number() { return m_iTestNum; }
__property void set_Number(int iNewNum) { m_iTestNum = iNewNum; }
// You will now have a property of TestClass called "Number"

protected:

private:
int m_iTestNum;
};

Hope that helps!

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top