471,079 Members | 946 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,079 software developers and data experts.

error C2259: cannot instantiate abstract class - then how do you do it?!

In C# we can go:

<foo.cs>
// Create a serializable class
[Serializable]
public class Foo : ISerializable
{
public void GetObjectData(SerializationInfo info,
StreamingContext context)
{};
}

// In our application
void MakeFoo()
{
Foo f = new Foo();
}
But in C++, I'm attempting:

<Foo.h>
[Serializable]
public __gc class Foo : public ISerializable
{
public:
Foo(){};
void GetObjectData(SerializationInfo* info,
StreamingContext* context);
};

<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}

I've been trying to get this to work for a number of hours now with no
success - any hints?

Cheers

- Si.

Nov 17 '05 #1
7 10412
First off, it needs to be:
Foo *foo = new Foo();

If you click on the 'Output' tab (probably next to the task list) while
you've got the error highlighted, it will tell you which functions it thinks
you haven't implemented.

Steve

"Simon Bond" <sichbo at kridabo dot com> wrote in message
news:ul**************@tk2msftngp13.phx.gbl...
In C# we can go:

<foo.cs>
// Create a serializable class
[Serializable]
public class Foo : ISerializable
{
public void GetObjectData(SerializationInfo info,
StreamingContext context)
{};
}

// In our application
void MakeFoo()
{
Foo f = new Foo();
}
But in C++, I'm attempting:

<Foo.h>
[Serializable]
public __gc class Foo : public ISerializable
{
public:
Foo(){};
void GetObjectData(SerializationInfo* info,
StreamingContext* context);
};

<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}

I've been trying to get this to work for a number of hours now with no
success - any hints?

Cheers

- Si.

Nov 17 '05 #2
"Simon Bond" <sichbo at kridabo dot com> wrote:
In C# we can go:

<foo.cs>
// Create a serializable class
[Serializable]
public class Foo : ISerializable
{
public void GetObjectData(SerializationInfo info,
StreamingContext context)
{};
}

// In our application
void MakeFoo()
{
Foo f = new Foo();
}
But in C++, I'm attempting:

<Foo.h>
[Serializable]
public __gc class Foo : public ISerializable
{
public:
Foo(){};
void GetObjectData(SerializationInfo* info,
StreamingContext* context);
};

<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}

I've been trying to get this to work for a number of hours now with no
success - any hints?


Hint: Look carefully at the signature of your GetObjectData and compare it
to the docs:

ISerializable.GetObjectData Method
http://msdn.microsoft.com/library/de...asp?frame=true

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #3
On Thu, 15 Jul 2004 11:59:23 -0300, "Simon Bond" <sichbo at kridabo
dot com> wrote:
But in C++, I'm attempting:

<Foo.h>
[Serializable]
public __gc class Foo : public ISerializable
{
public:
Foo(){};
void GetObjectData(SerializationInfo* info,
StreamingContext* context);
};

<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}

I've been trying to get this to work for a number of hours now with no
success - any hints?


Read the documentation for ISerializable.

Hint: (void GetObjectData(
SerializationInfo* info,
StreamingContext context
); - you're hiding that function, not overriding it)

Tom
Nov 17 '05 #4
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote:
<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}


First off, it needs to be:
Foo *foo = new Foo();


While required in C#, those parens are optional in C++. For a managed type,
I'm unaware they make any difference. For an unmanaged type that has no
ctors, the parens cause members of built-in types to be zero-initialized.
Without the parens, those members would be uninitialized.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #5
Ah-ha!

Thanks, Doug. Just a * in there where it shouldn't have been.

Your help is greatly appreciated.

- Si
"Doug Harrison [MVP]" <ds*@mvps.org> wrote in message
news:jk********************************@4ax.com...
"Simon Bond" <sichbo at kridabo dot com> wrote:
In C# we can go:

<foo.cs>
// Create a serializable class
[Serializable]
public class Foo : ISerializable
{
public void GetObjectData(SerializationInfo info,
StreamingContext context)
{};
}

// In our application
void MakeFoo()
{
Foo f = new Foo();
}
But in C++, I'm attempting:

<Foo.h>
[Serializable]
public __gc class Foo : public ISerializable
{
public:
Foo(){};
void GetObjectData(SerializationInfo* info,
StreamingContext* context);
};

<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}

I've been trying to get this to work for a number of hours now with no
success - any hints?
Hint: Look carefully at the signature of your GetObjectData and compare it
to the docs:

ISerializable.GetObjectData Method

http://msdn.microsoft.com/library/de...asp?frame=true
--
Doug Harrison
Microsoft MVP - Visual C++

Nov 17 '05 #6
Thanks, Tom.

"tom_usenet" <to********@hotmail.com> wrote in message
news:ka********************************@4ax.com...
On Thu, 15 Jul 2004 11:59:23 -0300, "Simon Bond" <sichbo at kridabo
dot com> wrote:
But in C++, I'm attempting:

<Foo.h>
[Serializable]
public __gc class Foo : public ISerializable
{
public:
Foo(){};
void GetObjectData(SerializationInfo* info,
StreamingContext* context);
};

<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}

I've been trying to get this to work for a number of hours now with no
success - any hints?


Read the documentation for ISerializable.

Hint: (void GetObjectData(
SerializationInfo* info,
StreamingContext context
); - you're hiding that function, not overriding it)

Tom

Nov 17 '05 #7

"Doug Harrison [MVP]" <ds*@mvps.org> wrote in message
news:lh********************************@4ax.com...
"Steve McLellan" <sjm.NOSPAM AT fixerlabs DOT com> wrote:
<Foo.cpp>
// In the application
void MakeFoo()
{
Foo* foo = new Foo; //error C2259: cannot instantiate abstract class
}
First off, it needs to be:
Foo *foo = new Foo();


While required in C#, those parens are optional in C++. For a managed

type, I'm unaware they make any difference. For an unmanaged type that has no
ctors, the parens cause members of built-in types to be zero-initialized.
Without the parens, those members would be uninitialized.


I stand corrected :-) I've always used them out of habit, and possibly
because Java requires them (unless it doesn't, in which case it's only
habit).
Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by ernesto | last post: by
4 posts views Thread by Andrew K | last post: by
1 post views Thread by Andreas Poller | last post: by
3 posts views Thread by Angus | last post: by
reply views Thread by SantaClaus | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.