Compiling Code - error CS1056 '`' - codedom

I am trying to compile a code using my own compiler (CodeDOM), but on codes like this:
390. sealed class FunctorComparer`1 {
421. public System.Array+FunctorComparer`1[T] () {}
448. abstract public interface IEnumerator`1 {
... (1676 matches) ...
i am getting this error:
c:\Users\[Username]\AppData\Local\Temp\0z4zag32.0.cs(390,29) : error CS1056: Unexpected character '`'
what am I missing?
[EDIT (1, "16:25", "4 May")]
the code i m trying to compile is not written by me. I don't know what that
character stands for, learning it. But i found that on this site
http://submain.com/ghostdoc/samples/PowerCollections/HTML/html/75549028.htm
it is being used, and it is strange the CodeDOM doesnt parse it.

The backticks should be removed from the code. This is what the error code is hinting at.
They were likely added due to an overzealous escaping on the part of the system you're getting this code sample from.

The name of any member (field, property, method, class) can not contain the character
'`'
If you are reading details from
System.Reflection
It will add this character, i m not sure it s need, may be because it is overidding a virtual member x times. like
System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult] //1 time
System.Threading.Tasks.Task`6[System.Threading.Tasks.VoidTaskResult] //6 times
Just taking the first part of the declaration is complete, and contains all the informations the computer needs to do the work.
from
System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]
to
System.Threading.Tasks.Task

Related

How do I directly make an val binding to an option value in SML?

val SOME i = Int.fromString e
I have a line like this on my code and smlnj shows me this warning
vm.sml:84.7-84.32 Warning: binding not exhaustive
SOME i = ...
Is this bad practice? Should I use a function to handle the option or am I missing something?
If you're just working on a small script you'll run once, it's not necessarily bad practice: If Int.fromString e fails (and returns NONE instead of SOME _), then the value binding will fail and an exception will be raised to the appropriate handler (or the program will exit, if ther is no handler). To disable this warning, you can run the top-level statement (for SML-NJ 110.96): Control.MC.bindNonExhaustiveWarn := false;.
As an alternative approach, you could throw a custom exception:
val i =
case Int.fromString e
of SOME i => i
| NONE => raise Fail ("Expected string value to be parseable as an int; got: " ^ e)
The exception message should be written in a way that's appropriate to the provenance of the e value. (If e comes from command-line input, the program should tell the user that a number was expected there; if e comes from a file, the program should tell the user which file is formatted incorrectly and where the formatting error was found.)
As yet another alternative: If your program is meant to be long-running and builds up a lot of state, it wouldn't be very user-friendly if the program crashed as soon as the user entered an ill-formed string on the command line. (The user would be quite sad in this case, as all the state they built up in the program would have been lost.) In this case, you could repeatedly read from stdin until the user types in input that can be parsed as an int. This is incidentally more-or-less what the SML/NJ REPL does: instead of something like val SOME parsedProgram = SMLofNJ.parse (getUserInput ()), it would want to do something like:
fun getNextParsedProgram () =
case SMLofNJ.parse (getUserInput ())
of NONE => (print "ERROR: failed to parse\n"; getNextParsedProgram ())
| SOME parsedProgram => parsedProgram
In summary,
For a short-lived script or a script you don't intend on running often, turning off the warning is a fine option.
For a program where it's unexpected that e would be an unparseable string, you could raise a custom exception that explains what went wrong and how the user can fix it.
For longer-lived programs where better error handling is desired, you should respect the NONE case by pattern-matching on the result of fromString, which forces you to come up with some sort of error-handling behavior.

error using frequncycounter library in arduino mega

dear
i wrote this code to calculate wind speed from anemometer
below the error message
windspeedcode2:15: error: 'FreqCount' is not a class, namespace, or
enumeration
FreqCount::f_comp= 8; // Set compensation to 12
^
windspeedcode2:16: error: 'FreqCount' is not a class, namespace, or
enumeration
FreqCount::start(100); // Start counting with gatetime of
100ms
^
windspeedcode2:17: error: 'FreqCounter' has not been declared
while (FreqCounter::f_ready == 0) // wait until counter
ready
^
windspeedcode2:19: error: 'FreqCount' is not a class, namespace, or
enumeration
freq=FreqCount::f_freq;//read frequency value
^
exit status 1 'FreqCount' is not a class, namespace, or enumeration
This report would have more information with "Show verbose output
during compilation" option enabled in File -> Preferences.
:: is the scope resolution operator for defining the same function outside the class
. is the dot operator used to call a member function (or member variable) on a object.
An example would be (assuming a instance named FreqCount exist in you library header): FreqCount.f_comp= 8;
Only if f_comp is a static class member variable can it be accessed is you called it: FreqCount::f_comp= 8; But that is unlikely for a library.
So what is in your header and where does the library come from?
thank you for your help the problem has been solved by downloading another library
as shown in picture

How to pass a vector as parameter to a c++ library from a CLI/C++ Wrapper?

I have found similar questions but none that worked for my situation, so I am asking my own.
I want to use a library function that takes a pointer to a std::vector, and fills it with data.
I already have a C++/CLI Wrapper set up.
I am currently trying to instantiate the vector in the wrapper,
private:
std::vector<int>* outputVector
and in the constructor, I instantiate it :
outputVector = new std::vector<int>();
Now, in the wrapper method that calls the c++ library function :
m_pUnmanagedTPRTreeClass->GetInRegion(..., &outputVector)
I omitted the other parameters because they dont matter for this case. I can already use other functions of the library and they work without a problem. I just can't manage to pass a pointer to a std::vector.
With the code like this, I get the error message :
error C2664: 'TPSimpleRTree<CT,T>::GetInRegion' : cannot convert parameter 3 from 'cli::interior_ptr<Type>' to 'std::vector<_Ty> &'
I have tried removing the "&", as I am not great at C++ and am unsure how to correctly use pointers. Then, the error becomes :
error C2664: 'TPSimpleRTree<CT,T>::GetInRegion' : cannot convert parameter 3 from 'std::vector<_Ty> *' to 'std::vector<_Ty> &'
EDIT: I have tried replacing "&" by "*", it does not work, I get the error :
cannot convert from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
The signature of the c++ function for the vector is so :
GetInRegion(..., std::vector<T*>& a_objects)
Given the signature:
GetInRegion(..., std::vector<T*>& a_objects)
You would call this (in C++ or C++/CLI) like:
std::vector<int*> v;
m_pUnmanagedTPRTreeClass->GetInRegion(..., v);
Then you can manipulate the data as needed or marshall the data into a .Net container.
'std::vector<_Ty> *' to 'std::vector<_Ty> &'
is self explanatory, you need to dereference instead of taking a pointer, so instead of:
m_pUnmanagedTPRTreeClass->GetInRegion(..., &outputVector)
use:
m_pUnmanagedTPRTreeClass->GetInRegion(..., *outputVector)
^~~~~~~!!
after your edit I see your getinregion signature is:
GetInRegion(..., std::vector<T*>& a_objects)
so it accepts std::vector where T is a pointer, while you want to pass to getinregion a std::vector where int is not a pointer.

How do I fill up a list in this large piece of code?

I wrote this Parser incorrectly. My professor says that I am using the tokens inappropriately. The problem is that I'm trying to access the tokens from an empty list. How can I possibly fill up the list with tokens in order to make sure that the program analyzes the tokens so the Eiffel code can execute. That is why I am getting this error:
raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : failed precondition from lexical_analyzers.ads:20
The code can be found here:
https://drive.google.com/file/d/0B3ZPyNRv7C3hV3NRUVBnN0prbEE/view?usp=sharing
The error comes from the lexical_analyzers.ads and the parsers.adb classes.
Your procedure Parse begins
procedure parse(p: in out Parser; f: out feature) is
tok: Token;
lex: Lexical_Analyzer;
var: Id;
com: Compound;
begin
so when you say
get_next_token(lex, tok);
which lex is it using? Answer: the empty one that you created in the declarations. You should be using p.lex.
And in the next line but one, your call to get_id doesn’t pass p:
var := get_id(tok);
and get_id repeats the pattern,
function get_id(tok: in Token) return Id is
par: Parser;
lex: Lexical_Analyzer;
tok1: Token := tok;
str: String := String(Tokens.get_lexeme(tok1));
begin
get_next_token(lex, tok1);
In this case, you’ve done it twice; you’ve created a local Parser and Lexical_Analyser instead of passing in the Parser (and its contained Lexical_Analyser).
This is a pattern you seem to have repeated in several places in the code.

Matlab: Attempt to reference field of non-structure array

I am using the Kernel Density Estimator toolbox form http://www.ics.uci.edu/~ihler/code/kde.html . But I am getting the following error when I try to execute the demo files -
>> demo_kde_3
KDE Example #3 : Product sampling methods (single, anecdotal run)
Attempt to reference field of non-structure array.
Error in double (line 10)
if (npd.N > 0) d = 1; % return 1 if the density exists
Error in repmat (line 49)
nelems = prod(double(siz));
Error in kde (line 39)
if (size(ks,1) == 1) ks = repmat(ks,[size(points,1),1]); end;
Error in demo_kde_3 (line 8)
p = kde([.1,.45,.55,.8],.05); % create a mixture of 4 gaussians for
testing
Can anyone suggest what might be wrong? I am new to Matlab and having a hard time to figure out the problem.
Thank You,
Try changing your current directory away from the #kde folder; you may have to add the #kde folder to your path when you do this. For example run:
cd('c:\');
addpath('full\path\to\the\folder\#kde');
You may also need to add
addpath('full\path\to\the\folder\#kde\examples');
Then see if it works.
It looks like function repmat (a mathworks function) is picking up the #kde class's version of the double function, causing an error. Usually, only objects of the class #kde can invoke that functions which are in the #kde folder.
I rarely use the #folder form of class definitions, so I'm not completely sure of the semantics; I'm curious if this has any effect on the error.
In general, I would not recommend using the #folder class format for any development that you do. The mathworks overhauled their OO paradigm a few versions ago to a much more familiar (and useful) format. Use help classdef to see more. This #kde code seems to predate this upgrade.
MATLAB gives you the code line where the error occurs. As double and repmat belong to MATLAB, the bug probably is in kde.m line 39. Open that file in MATLAB debugger, set a breakpoint on that line (so the execution stops immediately before the execution of that specific line), and then when the code is stopped there, check the situation. Try the entire code line in console (copy-paste or type it, do not single-step, as causing an uncatched error while single-stepping ends the execution of code in debugger), it should give you an error (but doesn't stop execution). Then try pieces of the code of that code line, what works as it should and what not, eg. does the result of size(points, 1) make any sense.
However, debugging unfamiliar code is not an easy task, especially if you're a beginner in MATLAB. But if you learn and understand the essential datatypes of MATLAB (arrays, cell arrays and structs) and the different ways they can be addressed, and apply that knowledge to the situation on the line 39 of kde.m, hopefully you can fix the bug.
Repmat calls double and expects the built-in double to be called.
However I would guess that this is not part of that code:
if (npd.N > 0) d = 1; % return 1 if the density exists
So if all is correct this means that the buil-tin function double has been overloaded, and that this is the reason why the code crashes.
EDIT:
I see that #Pursuit has already addressed the issue but I will leave my answer in place as it describes the method of detection a bit more.

Resources