As you see i have a check method defined in the class definition. The problem is that i cant compare the two characters since it doesnt let me to define char e in the class defintion. How do i fix this task? a==e is written by me for reference of what i have been doing, but i get the error message:
Syntax Error(s)
tester.java:7: error: cannot find symbol
if(a==e){
^
symbol: variable e
location: class tester
1 error
Thankful for any help!
public static void check (char a){`
`if(a==e){`
`System.out.println("if");`
`}else{`
`System.out.println("else");
}
}
Related
I know that when a class member is private, it means nothing other than that class can access it, and the way to solve it is to define it as protected, but what type of error does it cause, for example:
class Derived;
class base{
public:
base(int a){};
private:
int a;
};
class Derived: public base {
public:
Derived(int a) :base(a){}
void run(){
this->a=5; // ** (this line is an error)
}
};
so the question is, is the error caused by line ** a preprocessor error or a compilation error, and why? also what are preprocessor errors?
I never heard the term "preprocessor error" before. However, if you mistype a preprocessor directive, for example:
#incld <string>
Then you get an error along the line of
<source>:1:2: error: invalid preprocessing directive #incld; did you mean #include?
1 | #incld <string>
| ^~~~~
| include
Because the preprocessor cannot process the directive incld. Altough an uncommon term, this can be called "preprocessor error", because the error happens while running the preprocessor. Actual compilation didn't start yet.
On the other hand, your code results in the error message:
<source>: In member function 'void Derived::run()':
<source>:13:15: error: 'int base::a' is private within this context
13 | this->a=5; // ** (this line is an error)
| ^
<source>:6:9: note: declared private here
6 | int a;
| ^
This error has nothing to do with the preprocessor. There is nothing to be preprocessed by the preprocessor in your code. Attempting to access a private member outside of the class is an error that comes up during the compilation stage.
I have a third-party library, and I want to use one of the supplied constructors.
ex.h:
/** Construct example from string and a list of symbols. The input grammar is
* similar to the GiNaC output format. All symbols and indices to be used
* in the expression must be specified in a lst in the second argument.
* Undefined symbols and other parser errors will throw an exception. */
ex(const std::string &s, const ex &l);
I tried the following:
symbol x("x");
ex e("x^2",x);
Unfortunately the usage of this constructor is incorrect. I get the following error message:
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found
All documentation that is provided is the comment above the declaration. I am a C++ novice, so I have no idea what is wrong.
I tried the suggestion in the first answer like the following:
symbol x("x");
ex expression;
ex e("x^2",expression);
std::cout << diff(e,x) << std::end
This results in the following error message:
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found
(lldb)
Note: I tried using e and expression in diff().
You need to provide an ex reference, not a symbol reference;
Try this:
ex MyEx1; //This will call to the ex default constructor for MyEx1, if it exist.
ex e("x^2",MyEx1); //This will call to the ex constructor that you want to use for e.
The second argument should be a list of symbols occuring in the string (more precisely, a GiNaC::ex handling a GiNaC::lst). This works:
symbol x("x");
ex e("x^2", lst{x});
The idea is that it should work with more than just one symbol:
symbol x("x"), y("y");
ex e("x^2-2*x*y+y^2", lst{x,y});
cout << diff(e, x) << endl; // prints "2*x-2*y" or similar
I am trying to build an old binutils (2.13). getting the error ./config/obj-elf.c:364: error: invalid type argument of ‘->’ (have ‘int’) on the next line :
if (symbol_get_obj (symbolP)->local)
{...
the function symbol_get_obj :
OBJ_SYMFIELD_TYPE *
symbol_get_obj (s)
symbolS *s;
{
if (LOCAL_SYMBOL_CHECK (s))
s = local_symbol_convert ((struct local_symbol *) s);
return &s->sy_obj;
}
OBJ_SYMFIELD_TYPE is defined to be :
#define OBJ_SYMFIELD_TYPE struct elf_obj_sy
and elf_obj_sy is
struct elf_obj_sy
{
/* Whether the symbol has been marked as local. */
int local;
/* Use this to keep track of .size expressions that involve
differences that we can't compute yet. */
expressionS *size;
/* The name specified by the .symver directive. */
char *versioned_name;
#ifdef ECOFF_DEBUGGING
/* If we are generating ECOFF debugging information, we need some
additional fields for each symbol. */
struct efdr *ecoff_file;
struct localsym *ecoff_symbol;
valueT ecoff_extern_size;
#endif
};
couldn't understand what is wrong with this code ... any advice ?
Based on the error message, one possible reason is that the declaration of the function symbol_get_obj fails to appear before the place you call it, which makes the return value default to type int, an invalid type for operator ->. You might want to check this. Make sure the correct presence of symbol_get_obj's declaration through header file inclusion or explicit function prototype.
invalid type argument of ‘->’ (have ‘int’)
That can only make sense if
symbol_get_obj(symbolP)
returns int. Which it does not.
So, the only logical conclusion is that symbol_get_obj has not been declared at the point in the code where the error occurs. In which case the compiler will assume that it is a function that returns a value of type int. Which would then explain the error message.
I have the following decleration in file Order.h (Holdng class Order) :
void removeFromAlbum(int barcode);
and the following Implementation line:
void Order::removeFromAlbum(int barcode)
But, when im trying to call the function with a different file, Store.cpp (Order.h was included) with the following line :
order.removeFromAlbum(barcode);
I get the following error from eclipse :
Invalid arguments '
Candidates are:
void removeFromAlbum(int)
'
Eclipse is well defined.
Any suggestions ?
Edit :
This is the function when all the magic happens :
void Store::removeFromOrder(int ordNum, int barcode)
barcode is an int.
EDIT: Before the OP's edit, it was impossible to tell if barcode was an integer. This answer may, therefore, be invalid:
It looks like you're trying to call the function removeFromAlbum() with a type that isn't an int. Ensure that barcode is actually cast as an int.
class messageA {
};
class messageB {
};
template<class T>
class queue {
public:
virtual ~queue() {}
void submit(T& x) {}
};
class A : public queue<messageA>, public queue<messageB>
{
};
int main()
{
A aa;
aa.submit(messageA());
aa.submit(messageB());
}
My first thought is, the above code should be fine, as class A will contains 2 overloaded submit functions, which will accept messageA and messageB object.
However, the compiler gives me the following error :
May I know why there is an ambiguous? Isn't it is quite obvious that, for the 1st submit call, I want to call messageA version? For the 2nd submit call, I want to call messageB version?
------ Build started: Project: main, Configuration: Release Win32 ------
Compiling...
main.cpp
.\main.cpp(21) : error C2385: ambiguous access of 'submit'
could be the 'submit' in base 'queue<messageA>'
or could be the 'submit' in base 'queue<messageB>'
.\main.cpp(21) : error C3861: 'submit': identifier not found
.\main.cpp(22) : error C2385: ambiguous access of 'submit'
could be the 'submit' in base 'queue<messageA>'
or could be the 'submit' in base 'queue<messageB>'
.\main.cpp(22) : error C2664: 'queue<T>::submit' : cannot convert parameter 1 from 'messageB' to 'messageA &'
with
[
T=messageA
]
.\main.cpp(22) : error C3861: 'submit': identifier not found
I have no compiler right now, but I guess one inheritance could hide the other : The compiler will use Koenig Lookup to find the right symbol, and if I remember correctly, once the compiler find a suitable symbol (i.e., a method called "submit"), it will stop searching for others in parent and/or outer scopes.
In this case, I thought both inheriting classes would be searched for the symbol, but without your exact compiler (Visual C++ 2003 ? 2008 ? 2010 ?), I cannot guess much more.
After some thoughts, another possibility is that the compiler did find both symbols, but is unable to decide which to call (at that moment of symbol resolution, the compiler cares only for symbol name, not its exact prototype). I believe this last explanation to be the right one.
Try adding using statements in your derived classes :
class A : public queue<messageA>, public queue<messageB>
{
using queue<messageA>::submit ;
using queue<messageB>::submit ;
} ;
to bring both the submit methods directly in the A class scope.
Note, too, that your submit methods are taking messages as non-const reference, while in the constructor, your message parameters are temporaries (and thus, const r-values).
Re-writting the main as:
int main()
{
A aa;
messageA mA ;
messageA mB ;
aa.submit(mA);
aa.submit(mB);
}
could help compile (this could explain the compiler error on line 22).
Or you could change the prototype of your submit methods to accept const references instead of non-const references.
Note: Still without compiler, so trying to brain-debug your code... :-P ...
Something* smth1 = ((Base<Something> *)d)->createBase<Something>();
The above code works fine.