| uint32_t 'could not be resolved' and template inheritance issue. [message #1710454] |
Tue, 06 October 2015 15:51  |
Eclipse User |
|
|
|
Same old boring issue but I can't fix it. Porting code from MS VS which is lovely, easy and works. But not in eclipse. Default Include Paths are used. Added -std=c++11 flag to GCC C++ Compiler->Miscellaneous TAB, using LINUX GCC tool chain (yes, I'm using Linux).
Second problem is inheriting template code:
template<typename T>
class cSchedulerBase{
public: blar blar}
template<class T, std::size_t n, std::size_t p>
class cScheduler : private cSchedulerBase<T>{
blar blar}
Both defined in the same header file yet eclipse throws a wobbly:
class 'cScheduler<T, n, p>' does not have any field named 'cSchedulerBase' cScheduler.h /Scheduler/utilities line 62 C/C++ Problem
Yet its fine in MS VS. Tried all the forums ....
Any ideas much appreciated. Cheers Paul.
|
|
|
|
| Re: uint32_t 'could not be resolved' and template inheritance issue. [message #1710725 is a reply to message #1710577] |
Thu, 08 October 2015 12:46   |
Eclipse User |
|
|
|
Hi Paul,
I tried to mock-up your problem, but it all builds and runs fine in my case. I paste the code so that you can tell me what to add where in order to reproduce your error.
#include <iostream>
template<typename T>
class cSchedulerBase
{
public:
cSchedulerBase(std::size_t n, std::size_t p)
{
std::cout << "Created Scheduler Base: n=" << n << " p=" << p << std::endl;
mT = new T();
};
virtual ~cSchedulerBase()
{
delete mT;
std::cout << "Scheduler Base destroyed" << std::endl;
};
private:
T *mT;
};
template<class T, std::size_t n, std::size_t p>
class cScheduler: private cSchedulerBase<T>
{
public:
cScheduler() : cSchedulerBase<T>(n, p)
{
std::cout << "Created Scheduler" << std::endl;
};
virtual ~cScheduler()
{
std::cout << "Scheduler destroyed" << std::endl;
};
};
class TestClass
{
public:
TestClass()
{
std::cout << "Test class created" << std::endl;
};
virtual ~TestClass()
{
std::cout << "Test class destroyed" << std::endl;
};
};
int main()
{
cScheduler<TestClass, 2, 2> *c = new cScheduler<TestClass, 2, 2>();
delete c;
return 0;
}
GCC output:
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/testTemplate.d" -MT"src/testTemplate.d" -o "src/testTemplate.o" "../src/testTemplate.cpp"
Output:
Created Scheduler Base: n=2 p=2
Test class created
Created Scheduler
Scheduler destroyed
Test class destroyed
Scheduler Base destroyed
Cheers,
Mateusz
|
|
|
|
| Re: uint32_t 'could not be resolved' and template inheritance issue. [message #1710751 is a reply to message #1710734] |
Thu, 08 October 2015 17:23   |
Eclipse User |
|
|
|
I don't think it's Eclipse that's getting the error. It's g++ and Eclipse is just reporting it.
I also tried to compile Mateusz's example and it compiled without errors.
Usually, I would suspect a missing quote,';', ')' or '}' in a preceding include that confuses the compiler but you say it works fine with MSVS. There are subtle differences between MS and gcc but I don't think they apply here. More likely the definition of cSchedulerBase is missing (by perhaps some missing punctuation as I said before) or there is something that results in gcc looking for a different signature than the one defined by cSchedulerBase. Maybe the parameters you are trying to pass aren't really the same type?
EDIT:
I tried altering the definition of cScheduler by removing the parent in the declaration and got:
template<class T, std::size_t n, std::size_t p>
class cScheduler //: private cSchedulerBase<T>
{
public:
cScheduler() : cSchedulerBase<T>(n, p)
{
std::cout << "Created Scheduler" << std::endl;
};
virtual ~cScheduler()
{
std::cout << "Scheduler destroyed" << std::endl;
};
};
gcc output:
src/main.cpp: In instantiation of 'cScheduler<T, n, p>::cScheduler() [with T = TestClass; long unsigned int n = 2ul; long unsigned int p = 2ul]':
src/main.cpp:51:67: required from here
src/main.cpp:26:39: error: type 'cSchedulerBase<TestClass>' is not a direct base of 'cScheduler<TestClass, 2ul, 2ul>'
cScheduler() : cSchedulerBase<T>(n, p)
^
Note that it detected cSchedulerBase<T> as a class and assumed you were trying to initialize it. I then altered the code to:
template<class T, std::size_t n, std::size_t p>
class cScheduler //: private cSchedulerBase<T>
{
public:
cScheduler() : foo(0) //: cSchedulerBase<T>(n, p)
{
std::cout << "Created Scheduler" << std::endl;
};
virtual ~cScheduler()
{
std::cout << "Scheduler destroyed" << std::endl;
};
};
gcc outut:
src/main.cpp: In constructor 'cScheduler<T, n, p>::cScheduler()':
src/main.cpp:26:17: error: class 'cScheduler<T, n, p>' does not have any field named 'foo'
cScheduler() : foo(0) //cSchedulerBase<T>(n, p)
foo wasn't defined anywhere and the compiler assumed it was supposed to be a part of the cScheduler class. It seems your problem is that cSchedulerBase is not being defined as a class for whatever reason.
[Updated on: Thu, 08 October 2015 17:51] by Moderator
|
|
|
| Re: uint32_t 'could not be resolved' and template inheritance issue. [message #1710798 is a reply to message #1710751] |
Fri, 09 October 2015 07:16   |
Eclipse User |
|
|
|
Thanks David and Mateusz for your assistance but eclipse is doing my head in:
"Clean Project" cleans up the Console perspective but not the Problems perspective. Its best to shut down eclipse and reopen it. Why?
Residual errors seem to reappear after changes are made. Its best to shut down eclipse and reopen it. Why?
Closing adjacent projects has no effect on residual errors. When I mean residual errors I mean errors related to line numbers that no longer exist. Cleaning the project has no affect.
Deleting projects does not delete them in eclipse workspace. I have to physically move them into the rubbish bin.
So when I have a problem and want to start from a blank sheet, I can't. I want to be confident there isn't residual 'crap' lurking around. I "assume" there is an 'Iclean' facility that cleans old *.o files?
I have errors showing the file perspective that don't show up in the console. Before you say it - that's after performing a build. There is star marking the error, I do a build. The star is still there but nothing is mentioned in the console.
Now this is really doing my head in:
Please don't criticise code quality here. I'm just trying to make a point.
I have a main.cpp file. It includes cSheduler.h. My cSheduler class is defined in there.
ok. The compiler complains cSheduler is defined out of scope. Weird. I then move the definition to before main - i.e in global. The compiler still complains its out of scope. So I shut down eclipse - reopen it and recompile. The out of scope error disappears but then my original errors come back. Weird.
#include "cScheduler.h"
#include <vector>
#include <ctime>
#include <iostream>
#include <fstream>
#include <string>
struct structA{
int number;
std::string contents;
structA() {}
structA(std::string contents, int number): contents(contents), number(number) {}
};
void updateLogFileTx(int current_time, structA const& ele);
void updateLogFileChangeChannel(int current_time, char channel);
static const int TEN_SECONDS = 10;
cScheduler<structA, 10, 60> scheduler; So I move it here but the compiler doesn't notice until after an eclipse shut down and reopen.
int main()
{
// cScheduler<structA, 10, 60> scheduler; Produces OOS error - why?
|
|
|
|
|
|
|
| Re: uint32_t 'could not be resolved' and template inheritance issue. [message #1719870 is a reply to message #1710859] |
Tue, 12 January 2016 13:38  |
Eclipse User |
|
|
|
Quote:The eclipse compiler does not compile the edited changes until after they are saved. Grrrrrr! MSVS compiles unsaved changes (lovely).
While it is true that changes must be saved before compiling, you can save yourself some grief by ensuring all edited files are saved before compiling by going to Window -> Preferences -> General -> Workspace and checking Save automatically before build.
[Updated on: Tue, 12 January 2016 13:46] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04543 seconds