No appropriate default constructor available? - class

I've got a peculiar error writing some C++/CLI code. I'm trying to make a copy of a class which holds some data.
The class is defined as:
public ref class RawDataPacket
{
protected:
float* m_internalData;
public:
RawDataPacket(const float* newInternalData);
RawDataPacket(const RawDataPacket^ rdp);
RawDataPacket(RawDataPacket^ rdp);
RawDataPacket();
};
When I try and make use of the class as follows:
void SomeClass::SomeFunction( RawDataPacket^ rdp )
{
// Send a copy of the packet to anyone interested.
RawDataPacket^ rdp1 = gcnew RawDataPacket( rdp );
ForwardData( rdp1 );
}
I get:
error C2512: 'RawDataPacket' : no appropriate default constructor available
I thought that RawDataPacket(); had that covered? ..or am I missing something really obvious there?
[Edit] The body of RawDataPacket() looks like this:
RawDataPacket::RawDataPacket()
{
m_internalData = nullptr;
}
[Edit2] The full compiler output looks like this:
1>------ Build started: Project: MySoftware, Configuration: Debug Win32 ------
1>Compiling...
1>RawDataPacket.cpp
1>Controller.cpp
1>.\Controller.cpp(452) : error C2512: 'MySoftware::RawDataPacket' : no appropriate default constructor available
1>Build log was saved at "file://c:\Projects\Experiments\MySoftware\Debug\BuildLog.htm"
1>MySoftware - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

Got it! It occurred to me that I'd forward-declared the RawDataPacket class in the header of the Controller class.
I tried including the header in there and removing the forward declaration and it worked. So it turns out that despite forward-declaring the class I'd forgotten to include the header in Controller.cpp
That could have been a nasty one to find.. cheers for the help all!

use explicit before the constructor if you are having parameters for constructor.

Related

NetSuite SuiteScript - Constants And Inclusion

I have a NetSuite SuiteScript file (2.0) in which I want to include a small library of utilities I've built. I can do that fine, and access the functions in the included library. But I can't access the constants I've defined in that library - I have to re-declare them in the main file.
Here's the main file:
define(['N/record', 'N/search', './utils.js'],
function (record, search, utils) {
function pageInit(scriptContext) {
isUserAdmin = isCurrentUserAdmin(contextRecord);
if (isUserAdmin) {
alert('Administrator Role ID is ' + ADMINISTRATOR_ROLE);
// Do something for Admin users
}
return;
}
return {
pageInit: pageInit
};
});
You can see I include the file ./utils.js in it. Here's utils.js:
const ADMINISTRATOR_ROLE = 11;
function isCurrentUserAdmin(currentRecord) {
return ADMINISTRATOR_ROLE == nlapiGetRole();
}
That's the entire file - nothing else.
In the main file, the call to the function isCurrentUserAdmin works fine. It correctly tells me whether the current user is an admin. Note that I don't have to preface the call to isCurrentUserAdmin with utils. (utils.isCurrentUserAdmin doesn't work - it gives me the error JS_EXCEPTION TypeError utils is undefined). But when the code gets to the line that uses ADMINSTRATOR_ROLE, I get the error JS_EXCEPTION ReferenceError ADMINISTRATOR_ROLE is not defined. BTW, if I put the constant definition of ADMINISTRATOR_ROLE in the main file instead of utils.js, I get the same error when utils.js tries to use it. The only way I can get it to work is if I have the line defining the constant in both files.
Why does the inclusion work for the function, but not the constant? Am I including the library wrongly? I thought I'd have to use it as utils.isCurrentUserAdmin rather than just isCurrentUserAdmin, but to my surprise that's not the case, as I say above.
If you have utils.js like below, you can use utils.ADMINISTRATOR_ROLE and utils.isCurrentUserAdmin() in your main file.
/**
*#NApiVersion 2.0
*/
define ([],
function() {
const ADMINISTRATOR_ROLE = 11;
function isCurrentUserAdmin() {
// check here
}
return {
ADMINISTRATOR_ROLE: ADMINISTRATOR_ROLE,
isCurrentUserAdmin: isCurrentUserAdmin
};
});
Try
define(['N/record', 'N/search', 'SuiteScripts/utils']
You need to make sure any member you need to access in another module needs to be exported in the source module using the return statement

FSharpLint, how to use the rule "InterfaceNamesMustBeginWithI" in SuppressMessageAttribute?

[<SuppressMessage("NameConventions","InterfaceNamesMustBeginWithI")>] //No effect
[<SuppressMessage("NameConventions","InterfaceNames")>] //It's working
module Test=
type [<AllowNullLiteral>] MutationEvent =
abstract attrChange: float with get, set
...
Also, failed to search source code about "InterfaceNamesMustBeginWithI".
The name of the rule is InterfaceNames, so you can suppress it thus:
[<SuppressMessage("","InterfaceNames")>]
module Test =
...
Also note that the first argument to SuppressMessage is not used by fsharplint, so it can be anything (although not null, strangely enough!)
There are pointers to InterfaceNamesMustBeginWithI in the documentation, but this is not correct.

Using a Function pointer inside a class crashes the compiler (but works inside a function)

Reference class
class commandsListClass
{
public:
std::string name;
std::string description;
std::vector<std::string> commands;
columnHeaders headersRequired;
void (*function)(System::Object ^ );
std::string recoveryFileHeader;
void reset()
{
name = "";
description = "";
commands.clear();
headersRequired.reset();
recoveryFileHeader = "";
function = dummyFunc; // dummyFunc uses the same members as the intended - this is to ensure it is defined. DummyFunc is empty, returns void etc
}
commandsListClass()
{
reset();
}
};
Currently, if I run the below code, the compiler crashes
// This crashes the compiler
System::Threading::ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(global::commandsList[index].function ), ti);
1>------ Build started: Project: MyProject, Configuration: Release x64 ------
1> project.cpp
1>c:\users\guy\documents\visual studio 2012\projects\MyProject\MyProject\Form1.h(807): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1443)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If I declare a member inside the same function as I am making the call, and set it to the global::commandsList[index].function, it compiles and runs correctly
// This runs correctly
void (*func)(System::Object ^);
func = global::commandsList[index].function;
System::Threading::ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(func ), ti);
global::commandsList is a vector of type commandsListClass
Any ideas? Browsing Google and SO suggest changing the compiler to not optimize, which I've tried with no success. The code is written in such a way that:
That point in the code cannot be reached if index does not point to a valid member of the global::commandsList vector
The function variable is guaranteed to be set, either to the dummyFunc on creation, or the correct (requested) function as set elsewhere in the code.
Any help would be greatly appreciated.
Edit 1: This is using Visual Studio 2012, Windows 7 x64
Here's a simplified repo:
public delegate void MyDel(Object^);
void g(Object^) {}
struct A {
static void(*fs)(Object^);
void(*f)(Object^);
gcroot<MyDel^> del;
};
void(*fg)(Object^);
void h()
{
void (*f)(Object^);
A a;
gcnew MyDel(f);
gcnew MyDel(fg);
gcnew MyDel(a.fs);
a.del = gcnew MyDel(g);
//gcnew MyDel(a.f); // this line fails
// work around
f = a.f;
gcnew MyDel(f);
}
Only the non-static member variable fails. Seems like a compiler bug. Work around it by using a local intermediate.
Or better is Lucas's suggestion to use gcroot.

libspotify sp_search_type

When executing sp_search_create, there is a parameter for sp_search_type which is defined
typedef enum sp_search_type {
SP_SEARCH_STANDARD = 0,
SP_SEARCH_SUGGEST = 1,
} sp_search_type;
I don't see any change in the result. Is there a suggested way to handle this differently from a normal search ? For instance if we are implementing auto complete or am I missing something here.
Thanks,

Errors with a movieClip class

I have defined a class as
package telmate.com.audioB.volume {
import flash.display.MovieClip;
public class Volume_Bar extends MovieClip {
public static const BAR_WIDTH = 20;
public function Volume_Bar(op: Number, vol: Number) {
alpha = Util.clamp(op);
volume = vol;
}
private _volume:Number;// do we even need to store this?
public function set volume(v: Number){
_volume = v;
var f:uint = Util.clamp(v * totalFrames, 0, totalFrames - 1) + 1;
gotoAndStop(f);
}
}
}
and I am getting two errors: I am calling the constant BAR_WIDTH and instantiating it with parameters - new Volume_Bar(op, vol) -- and getting
/Users/dave/Documents/Audio/telmate/com/audioB/Audio_Bars.as, Line 152
1136: Incorrect number of arguments. Expected 0.
and
/Users/dave/Documents/Audio/telmate/com/audioB/Audio_Bars.as, Line 156
1119: Access of possibly undefined property BAR_WIDTH through a
reference with static type Class.
Why would this be?
Unfortunately, I don't know how specific I can be here, but...
That first error message indicates that when you're calling a function, you're passing arguments, but the function is not set up to handle arguments. Have you adjusted either the function itself, or the line of code that is calling it? (If you're calling through an event listener, be sure to include an argument in the function to hold the referring event. See documentation.)
What specifically is on Audio_bars.as, Line 152? That's where the error is occurring.
The second error seems to indicate that you haven't declared a function/variable by the name of "BAR_WIDTH". In reading your code, there doesn't appear to be an error in the declaration. Thus, you may be having a weird issue I've had before.
Hope that helps!