473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 10537
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Dario | last post by:
This is a technical C++ post regarding the Microsoft runtime error R6025 Pure Virtual Function Call that sometime occurs in programs compiled with Microsoft Visual C++ 6.0. Please consider the...
2
by: Yasutaka Ito | last post by:
Hi folks! I have a BaseForm class that inherits System.Windows.Forms.Form. It has a property, whose value I need supplied by the class that inherits it. The BaseForm usees the value supplied...
3
by: ernesto | last post by:
Hi everybody: I have the following implementations: class A { public: virtual int GetValue() = 0; };
4
by: Andrew K | last post by:
Hello, I have run into a problem with VC7 that worked in VC6. These two sections should be exactly the same... class test { public: virtual void blah(void)=0;}; void func(test) {} and
1
by: Andreas Poller | last post by:
Hello, I have the following problem: I have a class deriving from ICustomTypeDescriptor: public __gc class TPropertyBag : public ICustomTypeDescriptor { private: ...
3
by: Angus | last post by:
Hello I am getting this compile error: error C2259: 'PublicTON' : cannot instantiate abstract class due to following members: csta2less.h(1755) : see declaration of 'PublicTON' Class is like...
0
by: SantaClaus | last post by:
Hi all, I'm not able to compile out-of-proc component. The error I'm getting is Error 1 error C2259: 'CFile' : cannot instantiate abstract class I have given implementation for all of the...
1
by: gozlemci | last post by:
Hi everybody; During my coding, I have encountered a problem.I appreciate if anybody answer it. Here is the simplified code: //Header5.h #pragma once #include <string> using namespace std;
1
by: jainchar | last post by:
hello i m in trouble that my project is in vc++ with mfc.my program giving the error that error c2259:"CException" cannot instantiate abstract class. when i remove this error then my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.