Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » uint32_t 'could not be resolved' and template inheritance issue.(New to eclipse frustration. C++ linux eclipse version 4.8)
uint32_t 'could not be resolved' and template inheritance issue. [message #1710454] Tue, 06 October 2015 15:51 Go to next message
Eclipse UserFriend
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 #1710577 is a reply to message #1710454] Wed, 07 October 2015 12:13 Go to previous messageGo to next message
Eclipse UserFriend
Well no one is assisting so I'll add more info. The Microsoft Visual Studio is far better than the eclipse spanner.

Tried both CDT internal builder and GNU Make Builder. I guess the features I'm invoking are C++11. Eclipse is saying this:
16:55:25 **** Incremental Build of configuration Debug for project SchedulerNewA ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -o output -o src/main.o ../src/main.cpp
In file included from ../src/main.cpp:1:0:
../src/cScheduler.h: In constructor 'cScheduler<T, n, p>::cScheduler()':
../src/cScheduler.h:62:17: error: class 'cScheduler<T, n, p>' does not have any field named 'cSchedulerBase'
cScheduler() : cSchedulerBase(n, p), next_element(0){}

But cSchedulerBase is defined in the same header file above/before it is used. I have installed /usr/x86_64-w64-mingw32/include etc but including this in the project makes things worse.

Other posts mention adding 'g++ -std=c++0x *.cpp -o output' to Miscellaneous->other flags. Well *.cpp causes eclipse not to locate files so I had to remove that. I definitely need -std=c++0x. But you have to remember that gets removed to the default setting when changing the compiler selection when trying umpteen ways to fix it.

I need a definitive procedure so that C++11 functionality compiles.........


^
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #1710734 is a reply to message #1710725] Thu, 08 October 2015 14:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mateuz,

Thanks for your assistance. I've tried:
cScheduler() : cSchedulerBase<T>(n, p) too but no joy.

The compiler does not detect cSchedulerBase is inherited and I'm calling the base constructor directly. Its time for a beer. I'll test your version in my linux eclipse tomorrow. BTW this code I've copied directly from my MSVS stuff and its fine. I'll try again tomorrow. There iss someone out there. Smile Cheers. Paul.
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #1710822 is a reply to message #1710798] Fri, 09 October 2015 10:10 Go to previous messageGo to next message
Eclipse UserFriend
You call the thing a struct, but you're using it as a class.
Re: uint32_t 'could not be resolved' and template inheritance issue. [message #1710827 is a reply to message #1710798] Fri, 09 October 2015 10:42 Go to previous messageGo to next message
Eclipse UserFriend
Right! Got it working.
The eclipse compiler does not compile the edited changes until after they are saved. Grrrrrr! MSVS compiles unsaved changes (lovely).

Thanks for your help. It kept me going......... Smile
Re: uint32_t 'could not be resolved' and template inheritance issue. [message #1710836 is a reply to message #1710827] Fri, 09 October 2015 11:32 Go to previous messageGo to next message
Eclipse UserFriend
Now I'm flying. Its querky but I can now cope Smile
Re: uint32_t 'could not be resolved' and template inheritance issue. [message #1710859 is a reply to message #1710836] Fri, 09 October 2015 15:42 Go to previous messageGo to next message
Eclipse UserFriend
"Clean Project" cleans up the Console perspective but not the Problems perspective.
The eclipse compiler does not compile the edited changes until after they are saved. Grrrrrr! MSVS compiles unsaved changes (lovely).

You can delete the entries but they will reappear if either code analysis or the compiler reports an error (or warning)
Right click in the Problems View and Select All then Delete

Eclipse CDT (normally) uses the external program make for builds. It may optionally generate the makefile. The changes you've made will not be visible to the compiler (called by make) unless you commit them to the file with a save. Whether this is good or bad is a matter of opinion. If the save were never done then you would have an updated object or executable that's newer than the source but not recreatable from the existing source -- a potential for future confusion.


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 Go to previous message
Eclipse UserFriend
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

Previous Topic:Eclipse won't show me the finished program (C)
Next Topic:"cannt find a source file at C:/repo/*****/crt/crt_0.c" error when running gdb in eclipse
Goto Forum:
  


Current Time: Wed Oct 29 15:57:40 EDT 2025

Powered by FUDForum. Page generated in 0.04543 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top