473,698 Members | 2,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(S erializationInf o info,
StreamingContex t 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(S erializationInf o* info,
StreamingContex t* 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 10564
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******** ******@tk2msftn gp13.phx.gbl...
In C# we can go:

<foo.cs>
// Create a serializable class
[Serializable]
public class Foo : ISerializable
{
public void GetObjectData(S erializationInf o info,
StreamingContex t 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(S erializationInf o* info,
StreamingContex t* 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(S erializationInf o info,
StreamingContex t 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(S erializationInf o* info,
StreamingContex t* 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.G etObjectData 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(S erializationInf o* info,
StreamingContex t* 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(
SerializationIn fo* info,
StreamingContex t 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.c om...
"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(S erializationInf o info,
StreamingContex t 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(S erializationInf o* info,
StreamingContex t* 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.G etObjectData 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********@hot mail.com> wrote in message
news:ka******** *************** *********@4ax.c om...
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(S erializationInf o* info,
StreamingContex t* 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(
SerializationIn fo* info,
StreamingContex t 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.c om...
"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
46586
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 following simple illegal C++ program: class Listener { public: virtual void onEvent(int n) = 0;
2
2792
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 into this property in its Load event. So, I gave the BaseForm and the property 'abstract' modifier, and put the implementation of the property in the inherited class; say MyForm. However, when I did this, I no longer can open MyForm in the design...
3
17457
by: ernesto | last post by:
Hi everybody: I have the following implementations: class A { public: virtual int GetValue() = 0; };
4
1670
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
2823
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
3197
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 this: class PublicTON: public AsnType generated .h file:
0
1306
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 methods in CFile class, which is derived form interface IFile. The createInstance method of CFactory derived from IClassFactory is HRESULT CFactory::CreateInstance(IUnknown *pUnknownOuter, REFIID riid, void **ppv) {
1
2443
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
6433
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 project is giving the error in file afxres.rc .according to the error when i remove it and compile or debug the project then this can't save.so what should i do.please help me and can somebody give me the guideline that what is the afxres.rc file.
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7741
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.